A library for markdown parsing. This is just an Elm API built on top of the marked project which focuses on speed.
Turn a markdown string into an HTML element, using the defaultOptions.
bodyParagraph : Html
bodyParagraph =
Markdown.toHtml """
# Changing History
In addition to time travel, Elm Reactor lets you change history...
"""Some parser options so you can tweak things for your particular case.
* githubFlavored — overall reasonable improvements on the original
markdown parser as described here. This includes stuff like fenced
code blocks. There are some odd parts though, such as tables
and a setting to turn all newlines into newlines in the resulting output,
so there are settings to turn those on or off based on your preference.
* defaultHighlighting — a default language to use for code blocks that do
not have a language tag. So setting this to Just "elm" will treat all
unlabeled code blocks as Elm code. (This relies on highlight.js
as explained in the README here.)
* sanitize — this determines if all HTML should be escaped. If you
are parsing user markdown or user input can somehow reach the markdown
parser, you should almost certainly turn on sanitation. If it is just you
writing markdown, turning sanitation off is a nice way to do some HTML
tricks if it is needed.
* smartypants — This will automatically upgrade quotes to the
prettier versions and turn dashes into em dashes or en dashes
The Options used by the toElement and toHtml functions.
{ githubFlavored = Just { tables = False, breaks = False }
, defaultHighlighting = Nothing
, sanitize = False
, smartypants = False
}Maybe you want to get prettier quotes with a simple syntax. You can use modified parsing options.
options : Options
options =
{ defaultOptions | smartypants <- True }
toSmartElement : String -> Element
toSmartElement markdown =
Markdown.toElementWith options markdownMaybe you want to parse user input into markdown. To stop them from adding
<script> tags, you can use modified parsing options.
options : Options
options =
{ defaultOptions | sanitize <- True }
toMarkdown : String -> Html
toMarkdown userInput =
Markdown.toHtmlWith options userInput
Turn a markdown string into an HTML element, using the
defaultOptions.