From 1a1c45b33d258a9852a85a92f5a93d9288dde0d3 Mon Sep 17 00:00:00 2001 From: defanor Date: Thu, 21 Dec 2017 23:08:46 +0300 Subject: Set breadcrumbs for Plain elements' lines --- Pancake/Rendering.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Pancake') diff --git a/Pancake/Rendering.hs b/Pancake/Rendering.hs index e5d03c4..054edc5 100644 --- a/Pancake/Rendering.hs +++ b/Pancake/Rendering.hs @@ -400,11 +400,25 @@ readInline (P.Span attr i) = do -- | Reads lines of inline elements. readInlines :: [P.Inline] -> Renderer [StyledLine] -readInlines i = pure . concat <$> mapM readInline i +readInlines i = do + inlineBits <- concat <$> mapM readInline i + pure $ pure inlineBits + +-- | Akin to 'lines', but for 'Inline' elements. +inlines :: [P.Inline] -> [[P.Inline]] +inlines = flip inlines' [] + where inlines' :: [P.Inline] -> [P.Inline] -> [[P.Inline]] + inlines' [] [] = [] + inlines' [] curLine = [curLine] + inlines' (P.LineBreak : xs) curLine = curLine : inlines' xs [] + inlines' (other : xs) curLine = inlines' xs (curLine ++ [other]) -- | Renders a block element. renderBlock :: P.Block -> Renderer () -renderBlock (P.Plain i) = indented =<< readInlines i +renderBlock (P.Plain i) = + zipWithM_ (\l n -> withBreadcrumb n $ + (pure . concat <$> mapM readInline l) >>= indented) + (inlines i) [1..] renderBlock (P.Para i) = indented =<< readInlines i renderBlock (P.LineBlock i) = zipWithM_ (\l n -> withBreadcrumb n $ -- cgit v1.2.3