summaryrefslogtreecommitdiff
path: root/Pancake
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-01 08:55:39 +0300
committerdefanor <defanor@uberspace.net>2017-12-01 08:55:39 +0300
commit57228505d0f6e0acd739c39246de6342b2f33915 (patch)
treebcf30a732cdb6810dda1d262fca2a603d3f14769 /Pancake
parentdfcde74776fb403356e4e1f189975da7f5b3eedd (diff)
Reduce spacing between blocks
Insert empty lines conditionally instead of doing that between every pair of blocks. It can be improved further, but looks slightly better than it used to this way.
Diffstat (limited to 'Pancake')
-rw-r--r--Pancake/Rendering.hs31
1 files changed, 29 insertions, 2 deletions
diff --git a/Pancake/Rendering.hs b/Pancake/Rendering.hs
index a917104..55aabd6 100644
--- a/Pancake/Rendering.hs
+++ b/Pancake/Rendering.hs
@@ -484,9 +484,36 @@ renderBlock (P.Div attr b) = do
i $ renderBlocks b
renderBlock P.Null = pure ()
--- | Renders block elements with empy lines between them.
+-- | Checks whether a block is a list (ordered-, bullet-, or
+-- definition-).
+isList :: P.Block -> Bool
+isList P.OrderedList {} = True
+isList P.BulletList {} = True
+isList P.DefinitionList {} = True
+isList _ = False
+
+-- | Determines whether a line should be skipped before a block.
+skipBefore :: P.Block -> Bool
+skipBefore P.Header {} = True
+skipBefore P.Para {} = True
+skipBefore (P.Div _ (b:_)) = skipBefore b
+skipBefore _ = False
+
+-- | Determines whether a line should be skipped after a block.
+skipAfter :: P.Block -> Bool
+skipAfter P.Header {} = True
+skipAfter P.Para {} = True
+skipAfter (P.Div _ bs@(_:_)) = skipAfter $ last bs
+skipAfter b = isList b
+
+-- | Renders block elements with empty lines between some of them.
renderBlocks :: [P.Block] -> Renderer ()
-renderBlocks b = sequence_ (intersperse (storeLines [[]]) $ map renderBlock b)
+renderBlocks [] = pure ()
+renderBlocks [b] = renderBlock b
+renderBlocks (b1:bs@(b2:_)) = do
+ renderBlock b1
+ when (skipAfter b1 || skipBefore b2) $ storeLines [[]]
+ renderBlocks bs
-- | Renders a document.
renderDoc :: Int