diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Render.hs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/app/Render.hs b/app/Render.hs index 6cb0373..f4293c2 100644 --- a/app/Render.hs +++ b/app/Render.hs @@ -129,15 +129,6 @@ instance Render Markdown where instance Render [D.Node] where render = render . D.Node Nothing D.DOCUMENT --- TODO Fix spacing between markdown nodes --- --- The following code suffers from the problem that inline code such as `foo` is not separated correctly when surrounded by non-whitespace characters, ie. `foo`, or `foo`s. --- --- The reason for that is that we generally trim words within `TEXT` nodes, and then add the spaces back. --- --- Thus, we should not trim words. But we should still replace whitespace by `P.softline`s (ie. `P.fillSep`) for automatic paragraph wrapping. --- --- @topic markdown instance Render D.Node where render = maybe emptyDoc go . rec where @@ -146,7 +137,7 @@ instance Render D.Node where go (D.Node _ D.DOCUMENT ns) = vsep (intersperse (pretty ("" :: T.Text)) (map go ns)) go (D.Node _ D.THEMATIC_BREAK _) = pretty ("***" :: T.Text) - go (D.Node _ D.PARAGRAPH ns) = fillSep $ map go ns + go (D.Node _ D.PARAGRAPH ns) = hcat $ map go ns go (D.Node _ D.BLOCK_QUOTE ns) = styled [color Black] . fillSep $ pretty (">" :: T.Text) @@ -181,8 +172,20 @@ instance Render D.Node where hsep (map ((pretty ("- " :: T.Text)) <>) (map go ns)) go (D.Node _ D.ITEM ns) = fillSep (map go ns) go (D.Node _ (D.TEXT s) _) = - fillSep . map (pretty . T.strip) $ - T.words s + hcat + . intersperse softline + . map pretty + . ( \xs -> + -- first and last `T.null`-elements must be preserved as it may represents whitespace between sibling `D.Node`s. + if length xs >= 2 + then + head xs + : filter (not . T.null) (tail . init $ xs) + ++ [last xs] + else xs + ) + . T.split (== ' ') + $ s go (D.Node _ D.LINEBREAK _) = hardline go (D.Node _ (D.HTML_INLINE s) _) = styled [color Yellow] $ pretty (T.strip s) |