Markdown renderer that outputs mdgriffith/elm-ui Elements for dillonkearns/elm-markdown
renderer : Markdown.Renderer.Renderer (Element msg)
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 thematicBreak
is a horizontal rule. If you wanted to replace this
with a series of emoji, you could do this:
customRenderer : Renderer (Element msg)
customRenderer =
{ renderer
| thematicBreak =
Element.el [ Element.centerX ] <|
Element.text "🖤🖤🖤"
}
To use this with dillonkearns/elm-markdown, you would just pass it as an argument to Markdown.Renderer.render.
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.
default : String -> Result Error (List (Element msg))
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 --> True
defaultWrapped : String -> Result Error (Element msg)
Even 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