Markdown renderer that outputs mdgriffith/elm-ui Elements for dillonkearns/elm-markdown
Wrapper for the two types of error that can be output by Markdown.Parser.parse and Markdown.renderer.render
This type is returned by default and defaultWrapped in the Err case.
Fast-path to render Markdown; returns the output from Markdown.Renderer.render as a List (Element msg).
import Element exposing (Element)
import Result.Extra as ResultX
markdown : String
markdown =
"# This is a H1"
view : String -> Result Error (Element msg)
view md =
default md
|> Result.map
(Element.column
[ Element.width Element.fill
, Element.spacingXY 16 24
]
)
view markdown |> ResultX.isOk --> TrueEven faster path to render Markdown; wraps the output from default in
Element.column
[ Element.width Element.fill
, Element.spacingXY 16 24
]Here's how you could use it:
markdown : String
markdown =
"## This is a H2"
view : String -> Element msg
view md =
defaultWrapped md
|> Result.mapError
(\_ -> Element.text "Something went wrong!")
|> ResultX.merge
Default renderer. Since this value is a record, you can easily replace any of the field values with a function that has the correct signature.
For instance: the default
thematicBreakis a horizontal rule. If you wanted to replace this with a series of emoji, you could do this:To use this with dillonkearns/elm-markdown, you would just pass it as an argument to Markdown.Renderer.render.