summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <ilabdsf@gmail.com>2017-08-09 00:05:49 +0300
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-08 14:05:49 -0700
commitb50de96502b3edb27bd06887c0af011fdc76c2c2 (patch)
tree116fa7a76fbe8ba2ab83fb4aec62346278f27a67
parenta1cd7c3bfd973aca2b7a8f22a2c7f7fae7dc707b (diff)
Muse writer: insert two blanklines between lists of the same type (#3844)
-rw-r--r--src/Text/Pandoc/Writers/Muse.hs24
-rw-r--r--test/Tests/Writers/Muse.hs73
2 files changed, 96 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs
index 0383d9d86..3a5eefc18 100644
--- a/src/Text/Pandoc/Writers/Muse.hs
+++ b/src/Text/Pandoc/Writers/Muse.hs
@@ -102,12 +102,34 @@ pandocToMuse (Pandoc meta blocks) = do
Nothing -> return main
Just tpl -> renderTemplate' tpl context
+-- | Helper function for flatBlockListToMuse
+-- | Render all blocks and insert blank lines between the first two
+catWithBlankLines :: PandocMonad m
+ => [Block] -- ^ List of block elements
+ -> Int -- ^ Number of blank lines
+ -> StateT WriterState m Doc
+catWithBlankLines (b : bs) n = do
+ b' <- blockToMuse b
+ bs' <- flatBlockListToMuse bs
+ return $ b' <> blanklines n <> bs'
+catWithBlankLines _ _ = error "Expected at least one block"
+
-- | Convert list of Pandoc block elements to Muse
-- | without setting stTopLevel.
flatBlockListToMuse :: PandocMonad m
=> [Block] -- ^ List of block elements
-> StateT WriterState m Doc
-flatBlockListToMuse blocks = cat <$> mapM blockToMuse blocks
+flatBlockListToMuse bs@(BulletList _ : BulletList _ : _) = catWithBlankLines bs 2
+flatBlockListToMuse bs@(OrderedList (_, style1, _) _ : OrderedList (_, style2, _) _ : _) =
+ catWithBlankLines bs (if style1' == style2' then 2 else 0)
+ where
+ style1' = normalizeStyle style1
+ style2' = normalizeStyle style2
+ normalizeStyle DefaultStyle = Decimal
+ normalizeStyle s = s
+flatBlockListToMuse bs@(DefinitionList _ : DefinitionList _ : _) = catWithBlankLines bs 2
+flatBlockListToMuse bs@(_ : _) = catWithBlankLines bs 0
+flatBlockListToMuse [] = return mempty
-- | Convert list of Pandoc block elements to Muse.
blockListToMuse :: PandocMonad m
diff --git a/test/Tests/Writers/Muse.hs b/test/Tests/Writers/Muse.hs
index ebe5d45cd..5291a5ef0 100644
--- a/test/Tests/Writers/Muse.hs
+++ b/test/Tests/Writers/Muse.hs
@@ -93,6 +93,79 @@ tests = [ testGroup "block elements"
, " third definition :: third description"
]
]
+ -- Test that lists of the same type and style are separated with two blanklines
+ , testGroup "sequential lists"
+ [ "bullet lists" =:
+ bulletList [ para $ text "First"
+ , para $ text "Second"
+ , para $ text "Third"
+ ] <>
+ bulletList [ para $ text "Fourth"
+ , para $ text "Fifth"
+ ] =?>
+ unlines [ " - First"
+ , " - Second"
+ , " - Third"
+ , ""
+ , ""
+ , " - Fourth"
+ , " - Fifth"
+ ]
+ , "ordered lists of the same style" =:
+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "First"
+ , para $ text "Second"
+ ] <>
+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "Third"
+ , para $ text "Fourth"
+ ] =?>
+ unlines [ " I. First"
+ , " II. Second"
+ , ""
+ , ""
+ , " I. Third"
+ , " II. Fourth"
+ ]
+ , "ordered lists with equal styles" =:
+ orderedList [ para $ text "First"
+ , para $ text "Second"
+ ] <>
+ orderedListWith (1, Decimal, DefaultDelim) [ para $ text "Third"
+ , para $ text "Fourth"
+ ] =?>
+ unlines [ " 1. First"
+ , " 2. Second"
+ , ""
+ , ""
+ , " 1. Third"
+ , " 2. Fourth"
+ ]
+ , "bullet and ordered lists" =:
+ bulletList [ para $ text "First"
+ , para $ text "Second"
+ ] <>
+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "Third"
+ , para $ text "Fourth"
+ ] =?>
+ unlines [ " - First"
+ , " - Second"
+ , ""
+ , " I. Third"
+ , " II. Fourth"
+ ]
+ , "different style ordered lists" =:
+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "First"
+ , para $ text "Second"
+ ] <>
+ orderedListWith (1, Decimal, DefaultDelim) [ para $ text "Third"
+ , para $ text "Fourth"
+ ] =?>
+ unlines [ " I. First"
+ , " II. Second"
+ , ""
+ , " 1. Third"
+ , " 2. Fourth"
+ ]
+ ]
, testGroup "nested lists"
[ "nested ordered list" =: orderedList [ plain $ text "First outer"
, plain (text "Second outer:") <>