summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-22 08:45:02 +0300
committerdefanor <defanor@uberspace.net>2017-12-22 08:45:02 +0300
commitd096dd977c094378fd1ef36ca42a26bded3b6fe9 (patch)
treece76abaee6c6a2f3b178618c435d98567cd15b7c
parentaecf9cf8449d8f28b40af1295883c38a8cf2db25 (diff)
downloadpancake-d096dd977c094378fd1ef36ca42a26bded3b6fe9.zip
pancake-d096dd977c094378fd1ef36ca42a26bded3b6fe9.tar.gz
pancake-d096dd977c094378fd1ef36ca42a26bded3b6fe9.tar.bz2
Split inline elements into lines in readInlines
-rw-r--r--Pancake/Rendering.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/Pancake/Rendering.hs b/Pancake/Rendering.hs
index b5fd717..213512b 100644
--- a/Pancake/Rendering.hs
+++ b/Pancake/Rendering.hs
@@ -421,7 +421,17 @@ readInline (P.Span attr i) = do
readInlines :: [P.Inline] -> Renderer [StyledLine]
readInlines i = do
inlineBits <- concat <$> mapM readInline i
- pure $ pure inlineBits
+ pure $ styledLines inlineBits
+
+-- | Splits a list of styled elements into styled lines. Like
+-- 'inlines', but for processed elements.
+styledLines :: [Styled] -> [StyledLine]
+styledLines = styledLines' []
+ where
+ styledLines' cur [] = [cur]
+ styledLines' cur (x:xs)
+ | unstyled [x] == "\n" = cur : styledLines' [] xs
+ | otherwise = styledLines' (cur ++ [x]) xs
-- | Akin to 'lines', but for 'Inline' elements.
inlines :: [P.Inline] -> [[P.Inline]]