Update to latest markdown parser.

This commit is contained in:
Dillon Kearns 2019-09-23 10:30:21 -07:00
parent 3d3588455d
commit 79f81ceac1
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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)