NoRedInk / elm-formatted-text-19 / FormattedText.Markdown

A specific FormattedText type for inline markdown.

This intentionally does not support block-level markdown elements, as FormattedText is not suitable for that. If you have formatted inline strings embeded in a semantic structure you might want to create a custom type for that structure.


type Markdown
    = Code
    | Link String
    | Bold
    | Italic

The different types of inline formatting that Markdown supports.


type Block
    = ThematicBreak
    | Heading Basics.Int (FormattedText Markdown)
    | CodeBlock String
    | Paragraph (FormattedText Markdown)
    | BlockQuote (List Block)
    | UnOrderedList (List (List Block))
    | OrderedList (List (List Block))
    | PlainInline (FormattedText Markdown)

The types of block formatting Markdown supports.

parse : String -> List Block

Turn a markdown-formatted string into Blocks.

The inline portions of the Block structure will be instances of FormattedText.

parseInline : String -> Result String (FormattedText Markdown)

Turn a markdown-formatted string into a FormattedText. Parsing will fail if the markdown contains block-level styling, which is not supported.

view : List Block -> List (Html msg)

Render the markdown-formatted text as Html.

viewInline : FormattedText Markdown -> List (Html msg)

If you have your own logic for rendering the markdown block elements, you can call this function to render the inline portions of the Markdown.

If you want to render your markdown in a different way take a look at the implementation of this function to see how you can use FormattedText.chunks to do so in a simple way.