git.iko.soy/typeable/pandoc
on master help sign in
Muse writer: insert two blanklines between lists of the same type (#3844)
b50de96Alexander
src/Text/Pandoc/Writers/Muse.hs+23−1
@@ -102,12 +102,34 @@ pandocToMuse (Pandoc meta blocks) = do
102 Nothing -> return main
102 Nothing -> return main
103 Just tpl -> renderTemplate' tpl context
103 Just tpl -> renderTemplate' tpl context
104
104
105+-- | Helper function for flatBlockListToMuse
106+-- | Render all blocks and insert blank lines between the first two
107+catWithBlankLines :: PandocMonad m
108+ => [Block] -- ^ List of block elements
109+ -> Int -- ^ Number of blank lines
110+ -> StateT WriterState m Doc
111+catWithBlankLines (b : bs) n = do
112+ b' <- blockToMuse b
113+ bs' <- flatBlockListToMuse bs
114+ return $ b' <> blanklines n <> bs'
115+catWithBlankLines _ _ = error "Expected at least one block"
116+
105-- | Convert list of Pandoc block elements to Muse
117-- | Convert list of Pandoc block elements to Muse
106-- | without setting stTopLevel.
118-- | without setting stTopLevel.
107flatBlockListToMuse :: PandocMonad m
119flatBlockListToMuse :: PandocMonad m
108 => [Block] -- ^ List of block elements
120 => [Block] -- ^ List of block elements
109 -> StateT WriterState m Doc
121 -> StateT WriterState m Doc
110−flatBlockListToMuse blocks = cat <$> mapM blockToMuse blocks
122+flatBlockListToMuse bs@(BulletList _ : BulletList _ : _) = catWithBlankLines bs 2
123+flatBlockListToMuse bs@(OrderedList (_, style1, _) _ : OrderedList (_, style2, _) _ : _) =
124+ catWithBlankLines bs (if style1' == style2' then 2 else 0)
125+ where
126+ style1' = normalizeStyle style1
127+ style2' = normalizeStyle style2
128+ normalizeStyle DefaultStyle = Decimal
129+ normalizeStyle s = s
130+flatBlockListToMuse bs@(DefinitionList _ : DefinitionList _ : _) = catWithBlankLines bs 2
131+flatBlockListToMuse bs@(_ : _) = catWithBlankLines bs 0
132+flatBlockListToMuse [] = return mempty
111
133
112-- | Convert list of Pandoc block elements to Muse.
134-- | Convert list of Pandoc block elements to Muse.
113blockListToMuse :: PandocMonad m
135blockListToMuse :: PandocMonad m
test/Tests/Writers/Muse.hs+73
@@ -93,6 +93,79 @@ tests = [ testGroup "block elements"
93 , " third definition :: third description"
93 , " third definition :: third description"
94 ]
94 ]
95 ]
95 ]
96+ -- Test that lists of the same type and style are separated with two blanklines
97+ , testGroup "sequential lists"
98+ [ "bullet lists" =:
99+ bulletList [ para $ text "First"
100+ , para $ text "Second"
101+ , para $ text "Third"
102+ ] <>
103+ bulletList [ para $ text "Fourth"
104+ , para $ text "Fifth"
105+ ] =?>
106+ unlines [ " - First"
107+ , " - Second"
108+ , " - Third"
109+ , ""
110+ , ""
111+ , " - Fourth"
112+ , " - Fifth"
113+ ]
114+ , "ordered lists of the same style" =:
115+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "First"
116+ , para $ text "Second"
117+ ] <>
118+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "Third"
119+ , para $ text "Fourth"
120+ ] =?>
121+ unlines [ " I. First"
122+ , " II. Second"
123+ , ""
124+ , ""
125+ , " I. Third"
126+ , " II. Fourth"
127+ ]
128+ , "ordered lists with equal styles" =:
129+ orderedList [ para $ text "First"
130+ , para $ text "Second"
131+ ] <>
132+ orderedListWith (1, Decimal, DefaultDelim) [ para $ text "Third"
133+ , para $ text "Fourth"
134+ ] =?>
135+ unlines [ " 1. First"
136+ , " 2. Second"
137+ , ""
138+ , ""
139+ , " 1. Third"
140+ , " 2. Fourth"
141+ ]
142+ , "bullet and ordered lists" =:
143+ bulletList [ para $ text "First"
144+ , para $ text "Second"
145+ ] <>
146+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "Third"
147+ , para $ text "Fourth"
148+ ] =?>
149+ unlines [ " - First"
150+ , " - Second"
151+ , ""
152+ , " I. Third"
153+ , " II. Fourth"
154+ ]
155+ , "different style ordered lists" =:
156+ orderedListWith (1, UpperRoman, DefaultDelim) [ para $ text "First"
157+ , para $ text "Second"
158+ ] <>
159+ orderedListWith (1, Decimal, DefaultDelim) [ para $ text "Third"
160+ , para $ text "Fourth"
161+ ] =?>
162+ unlines [ " I. First"
163+ , " II. Second"
164+ , ""
165+ , " 1. Third"
166+ , " 2. Fourth"
167+ ]
168+ ]
96 , testGroup "nested lists"
169 , testGroup "nested lists"
97 [ "nested ordered list" =: orderedList [ plain $ text "First outer"
170 [ "nested ordered list" =: orderedList [ plain $ text "First outer"
98 , plain (text "Second outer:") <>
171 , plain (text "Second outer:") <>