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.
This commit is contained in:
John MacFarlane 2014-11-25 12:28:48 -08:00
parent 25e2c42347
commit d8fde9547e
2 changed files with 29 additions and 6 deletions

View file

@ -252,7 +252,7 @@ blockToRST (Table caption _ widths headers rows) = do
blockToRST (BulletList items) = do
contents <- mapM bulletListItemToRST items
-- ensure that sublists have preceding blank line
return $ blankline $$ vcat contents $$ blankline
return $ blankline $$ chomp (vcat contents) $$ blankline
blockToRST (OrderedList (start, style', delim) items) = do
let markers = if start == 1 && style' == DefaultStyle && delim == DefaultDelim
then take (length items) $ repeat "#."
@ -264,17 +264,17 @@ blockToRST (OrderedList (start, style', delim) items) = do
contents <- mapM (\(item, num) -> orderedListItemToRST item num) $
zip markers' items
-- ensure that sublists have preceding blank line
return $ blankline $$ vcat contents $$ blankline
return $ blankline $$ chomp (vcat contents) $$ blankline
blockToRST (DefinitionList items) = do
contents <- mapM definitionListItemToRST items
-- ensure that sublists have preceding blank line
return $ blankline $$ vcat contents $$ blankline
return $ blankline $$ chomp (vcat contents) $$ blankline
-- | Convert bullet list item (list of blocks) to RST.
bulletListItemToRST :: [Block] -> State WriterState Doc
bulletListItemToRST items = do
contents <- blockListToRST items
return $ hang 3 "- " contents
return $ hang 3 "- " $ contents <> cr
-- | Convert ordered list item (a list of blocks) to RST.
orderedListItemToRST :: String -- ^ marker for list item
@ -283,7 +283,7 @@ orderedListItemToRST :: String -- ^ marker for list item
orderedListItemToRST marker items = do
contents <- blockListToRST items
let marker' = marker ++ " "
return $ hang (length marker') (text marker') contents
return $ hang (length marker') (text marker') $ contents <> cr
-- | Convert defintion list item (label, list of blocks) to RST.
definitionListItemToRST :: ([Inline], [[Block]]) -> State WriterState Doc
@ -291,7 +291,7 @@ definitionListItemToRST (label, defs) = do
label' <- inlineListToRST label
contents <- liftM vcat $ mapM blockListToRST defs
tabstop <- get >>= (return . writerTabStop . stOptions)
return $ label' $$ nest tabstop (nestle contents)
return $ label' $$ nest tabstop (nestle contents <> cr)
-- | Convert list of Pandoc block elements to RST.
blockListToRST :: [Block] -- ^ List of block elements

View file

@ -136,7 +136,9 @@ Asterisks tight:
Asterisks loose:
- asterisk 1
- asterisk 2
- asterisk 3
Pluses tight:
@ -148,7 +150,9 @@ Pluses tight:
Pluses loose:
- Plus 1
- Plus 2
- Plus 3
Minuses tight:
@ -160,7 +164,9 @@ Minuses tight:
Minuses loose:
- Minus 1
- Minus 2
- Minus 3
Ordered
@ -181,13 +187,17 @@ and:
Loose using tabs:
1. First
2. Second
3. Third
and using spaces:
1. One
2. Two
3. Three
Multiple paragraphs:
@ -195,7 +205,9 @@ Multiple paragraphs:
1. Item 1, graf one.
Item 1. graf two. The quick brown fox jumped over the lazy dogs back.
2. Item 2.
3. Item 3.
Nested
@ -215,25 +227,30 @@ Heres another:
- Fee
- Fie
- Foe
3. Third
Same thing but with paragraphs:
1. First
2. Second:
- Fee
- Fie
- Foe
3. Third
Tabs and spaces
---------------
- this is a list item indented with tabs
- this is a list item indented with spaces
- this is an example list item indented with tabs
- this is an example list item indented with spaces
Fancy list markers
@ -300,8 +317,10 @@ Loose:
apple
red fruit
orange
orange fruit
banana
yellow fruit
@ -311,6 +330,7 @@ Multiple blocks with italics:
red fruit
contains seeds, crisp, pleasant to taste
*orange*
orange fruit
@ -335,6 +355,7 @@ apple
red fruit
computer
orange
orange fruit
@ -346,6 +367,7 @@ apple
red fruit
computer
orange
orange fruit
@ -644,6 +666,7 @@ LaTeX
- Heres some display math:
.. math:: \frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}
- Heres one that has a line break in it: :math:`\alpha + \omega \times x^2`.
These shouldnt be math: