diff --git a/examples/docs/elm-markdown-parser/Markdown/Parser.elm b/examples/docs/elm-markdown-parser/Markdown/Parser.elm index a7d3b972..ac4ca9cf 100644 --- a/examples/docs/elm-markdown-parser/Markdown/Parser.elm +++ b/examples/docs/elm-markdown-parser/Markdown/Parser.elm @@ -161,7 +161,7 @@ type alias Renderer view = , italic : String -> view -- TODO make this a `Result` so users can validate links - , link : { title : Maybe String, destination : String } -> String -> Result String view + , link : { title : Maybe String, destination : String } -> List view -> Result String view , image : { src : String } -> String -> Result String view , list : List view -> view , codeBlock : { body : String, language : Maybe String } -> view @@ -182,8 +182,19 @@ foldThing renderer { style, string } soFar = Just link -> case link.destination of Inlines.Link destination -> - renderer.link { title = link.title, destination = destination } string - :: soFar + case Advanced.run Inlines.parse string of + Ok styledLine -> + (renderStyled renderer styledLine + |> Result.andThen + (\children -> + renderer.link { title = link.title, destination = destination } children + ) + ) + :: soFar + + Err error -> + (error |> List.map deadEndToString |> List.map Err) + ++ soFar Inlines.Image src -> renderer.image { src = src } string diff --git a/examples/docs/src/MarkdownRenderer.elm b/examples/docs/src/MarkdownRenderer.elm index ff7516be..868569ce 100644 --- a/examples/docs/src/MarkdownRenderer.elm +++ b/examples/docs/src/MarkdownRenderer.elm @@ -76,6 +76,7 @@ view markdown = Err (error |> List.map Markdown.Parser.deadEndToString |> String.join "\n") +renderer : Markdown.Parser.Renderer (Element msg) renderer = { heading = heading , raw = @@ -92,9 +93,15 @@ renderer = |> Result.map (\() -> Element.link - [ Font.color Palette.color.primary + [ Element.htmlAttribute (Html.Attributes.style "display" "inline-flex") ] - { url = link.destination, label = Element.text body } + { url = link.destination + , label = + Element.paragraph + [ Font.color Palette.color.primary + ] + body + } ) , image = \image body -> @@ -234,7 +241,6 @@ code snippet = (Element.rgba 0 0 0 0.04) , Element.Border.rounded 2 , Element.paddingXY 5 3 - , Font.color (Element.rgba255 0 0 0 1) , Font.family [ Font.monospace ] ] (Element.text snippet)