git.iko.soy/typeable/pandoc
on master help sign in
Reverted "omit blank lines after list items," better fix for #1777.

Now we do as before, including blank lines after list items in loose lists (even though RST doesn't care -- this is just a matter of visual appeal). But we chomp any excess whitespace after the last list item, which solves #1777.

commitd8fde9547e2e684cb892b1c38a5c01cf4aec0fe9 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 25 Nov 2014, 12:28 (12 years ago) parent25e2c42
2 files changed+29−6
src/Text/Pandoc/Writers/RST.hs+6−6 tests/writer.rst+23
src/Text/Pandoc/Writers/RST.hs+6−6
@@ -252,7 +252,7 @@ blockToRST (Table caption _ widths headers rows) = do
252252blockToRST (BulletList items) = do
253253 contents <- mapM bulletListItemToRST items
254254 -- ensure that sublists have preceding blank line
255− return $ blankline $$ vcat contents $$ blankline
255+ return $ blankline $$ chomp (vcat contents) $$ blankline
256256blockToRST (OrderedList (start, style', delim) items) = do
257257 let markers = if start == 1 && style' == DefaultStyle && delim == DefaultDelim
258258 then take (length items) $ repeat "#."
@@ -264,17 +264,17 @@ blockToRST (OrderedList (start, style', delim) items) = do
264264 contents <- mapM (\(item, num) -> orderedListItemToRST item num) $
265265 zip markers' items
266266 -- ensure that sublists have preceding blank line
267− return $ blankline $$ vcat contents $$ blankline
267+ return $ blankline $$ chomp (vcat contents) $$ blankline
268268blockToRST (DefinitionList items) = do
269269 contents <- mapM definitionListItemToRST items
270270 -- ensure that sublists have preceding blank line
271− return $ blankline $$ vcat contents $$ blankline
271+ return $ blankline $$ chomp (vcat contents) $$ blankline
272272
273273-- | Convert bullet list item (list of blocks) to RST.
274274bulletListItemToRST :: [Block] -> State WriterState Doc
275275bulletListItemToRST items = do
276276 contents <- blockListToRST items
277− return $ hang 3 "- " contents
277+ return $ hang 3 "- " $ contents <> cr
278278
279279-- | Convert ordered list item (a list of blocks) to RST.
280280orderedListItemToRST :: String -- ^ marker for list item
@@ -283,7 +283,7 @@ orderedListItemToRST :: String -- ^ marker for list item
283283orderedListItemToRST marker items = do
284284 contents <- blockListToRST items
285285 let marker' = marker ++ " "
286− return $ hang (length marker') (text marker') contents
286+ return $ hang (length marker') (text marker') $ contents <> cr
287287
288288-- | Convert defintion list item (label, list of blocks) to RST.
289289definitionListItemToRST :: ([Inline], [[Block]]) -> State WriterState Doc
@@ -291,7 +291,7 @@ definitionListItemToRST (label, defs) = do
291291 label' <- inlineListToRST label
292292 contents <- liftM vcat $ mapM blockListToRST defs
293293 tabstop <- get >>= (return . writerTabStop . stOptions)
294− return $ label' $$ nest tabstop (nestle contents)
294+ return $ label' $$ nest tabstop (nestle contents <> cr)
295295
296296-- | Convert list of Pandoc block elements to RST.
297297blockListToRST :: [Block] -- ^ List of block elements
tests/writer.rst+23
@@ -136,7 +136,9 @@ Asterisks tight:
136136Asterisks loose:
137137
138138- asterisk 1
139+
139140- asterisk 2
141+
140142- asterisk 3
141143
142144Pluses tight:
@@ -148,7 +150,9 @@ Pluses tight:
148150Pluses loose:
149151
150152- Plus 1
153+
151154- Plus 2
155+
152156- Plus 3
153157
154158Minuses tight:
@@ -160,7 +164,9 @@ Minuses tight:
160164Minuses loose:
161165
162166- Minus 1
167+
163168- Minus 2
169+
164170- Minus 3
165171
166172Ordered
@@ -181,13 +187,17 @@ and:
181187Loose using tabs:
182188
1831891. First
190+
1841912. Second
192+
1851933. Third
186194
187195and using spaces:
188196
1891971. One
198+
1901992. Two
200+
1912013. Three
192202
193203Multiple paragraphs:
@@ -195,7 +205,9 @@ Multiple paragraphs:
1952051. Item 1, graf one.
196206
197207 Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
208+
1982092. Item 2.
210+
1992113. Item 3.
200212
201213Nested
@@ -215,25 +227,30 @@ Here’s another:
215227 - Fee
216228 - Fie
217229 - Foe
230+
2182313. Third
219232
220233Same thing but with paragraphs:
221234
2222351. First
236+
2232372. Second:
224238
225239 - Fee
226240 - Fie
227241 - Foe
242+
2282433. Third
229244
230245Tabs and spaces
231246---------------
232247
233248- this is a list item indented with tabs
249+
234250- this is a list item indented with spaces
235251
236252 - this is an example list item indented with tabs
253+
237254 - this is an example list item indented with spaces
238255
239256Fancy list markers
@@ -300,8 +317,10 @@ Loose:
300317
301318apple
302319 red fruit
320+
303321orange
304322 orange fruit
323+
305324banana
306325 yellow fruit
307326
@@ -311,6 +330,7 @@ Multiple blocks with italics:
311330 red fruit
312331
313332 contains seeds, crisp, pleasant to taste
333+
314334*orange*
315335 orange fruit
316336
@@ -335,6 +355,7 @@ apple
335355 red fruit
336356
337357 computer
358+
338359orange
339360 orange fruit
340361
@@ -346,6 +367,7 @@ apple
346367 red fruit
347368
348369 computer
370+
349371orange
350372 orange fruit
351373
@@ -644,6 +666,7 @@ LaTeX
644666- Here’s some display math:
645667
646668 .. math:: \frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}
669+
647670- Here’s one that has a line break in it: :math:`\alpha + \omega \times x^2`.
648671
649672These shouldn’t be math: