Inline rendering and helpers.
The inline type.
toHtml : Inline i -> Html msg
Transform an Inline into Html using the default html elements.
toHtml (Text "Inner text") == Html.text "Inner text"
toHtml HardLineBreak == Html.br [] []
toHtml (CodeInline code) == Html.code [] [ Html.text code ]
defaultHtml : Maybe (Inline i -> Html msg) -> Inline i -> Html msg
Transform an Inline into a Html, optionally using custom html elements to render inner inlines.
upperText : Inline i -> Html msg
upperText inline =
case inline of
Text str ->
Html.text (String.toUpper str)
_ ->
defaultHtml (Just upperText) inline
defaultHtml (Just upperText) (Text "hello") == text "hello"
defaultHtml (Just upperText) (Emphasis 2 [ Text "hello" ]) == strong [] [ text "HELLO" ]
upperText (Text "hello") == text "HELLO"
Note: If the first argument is Nothing
,
the default html elements will be used to render
the inner inlines.
extractText : List (Inline i) -> String
Extract the text from a list of inlines.
inlines : List (Inline i)
inlines =
[ Text "Heading with "
, Emphasis 1
[ Text "emphasis" ]
]
extractText inlines == "Heading with emphasis"
-- Original string: "Heading with *emphasis*"