elm-explorations / markdown / Markdown

A library for markdown parsing. This is just an Elm API built on top of the marked project which focuses on speed.

Parsing Markdown

toHtml : List (Html.Attribute msg) -> String -> Html msg

Turn a markdown string into an HTML element, using the defaultOptions.

recipe : Html msg
recipe =
   Markdown.toHtml [class "recipe"] """

# Apple Pie Recipe

First, invent the universe. Then bake an apple pie.

"""

Parsing with Custom Options


type alias Options =
{ githubFlavored : Maybe { tables : Basics.Bool
, breaks : Basics.Bool }
, defaultHighlighting : Maybe String
, sanitize : Basics.Bool
, smartypants : Basics.Bool 
}

Some parser options so you can tweak things for your particular case.

defaultOptions : Options

The Options used by the toElement and toHtml functions.

{ githubFlavored = Just { tables = False, breaks = False }
, defaultHighlighting = Nothing
, sanitize = True
, smartypants = False
}

toHtmlWith : Options -> List (Html.Attribute msg) -> String -> Html msg

Maybe you want to allow tables in your markdown?

myOptions : Options
myOptions =
    { githubFlavored = Just { tables = True, breaks = False }
    , defaultHighlighting = Nothing
    , sanitize = True
    , smartypants = False
    }

toMarkdown : String -> Html
toMarkdown userInput =
    Markdown.toHtmlWith myOptions [] userInput