pablohirafuji/elm-markdown/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Markdown

A library for markdown parsing and rendering.

Parsing Markdown

toHtml : String -> List (Html Never)

Turn a markdown string into a list of HTML elements, using the Config.defaultOptions and Config.defaultElements.


type Msg
    = MsgOfmyApp1
    | MsgOfmyApp2
    | MsgOfmyApp3
    | Markdown


markdownView : Html Msg
markdownView =
    Html.map (always Markdown)
        <| section []
        <| Markdown.toHtml "# Title with *emphasis*"

Parsing with Custom Options

withOptions : Options -> String -> List (Html Never)

Customize how soft line breaks (\n) are rendered and raw html tags are parsed.

customOptions : Options
customOptions =
    { softAsHardLineBreak = True
    , rawHtml = DontParse
    }


view : Html Never
view =
    div []
        <| Markdown.withOptions customOptions model.textarea

The demo demonstrate how each option affects the output.

customHtml : Options -> Elements -> String -> List (Html Never)

Customize how to render each element. The following examples demonstrate how to use it.

  • Render target="_blank" on links depending on the url. Demo / Code
  • Render images using figure and figcaption elements. Demo / Code