Avoid blank lines after tight sublists in org, haddock.

T.P.Writers.Shared `endsWithPlain` now returns True if
the list ends with a list which ends with a Plain.

See #7810.
This commit is contained in:
John MacFarlane 2022-01-08 23:09:06 -08:00
parent 1b7bdb1016
commit 61968047e4
5 changed files with 14 additions and 7 deletions

View file

@ -219,7 +219,7 @@ bulletListItemToOrg :: PandocMonad m => [Block] -> Org m (Doc Text)
bulletListItemToOrg items = do
exts <- gets $ writerExtensions . stOptions
contents <- blockListToOrg (taskListItemToOrg exts items)
return $ hang 2 "- " contents $$
return $ hang 2 "- " (chomp contents) $$
if null items || endsWithPlain items
then cr
else blankline
@ -237,7 +237,7 @@ orderedListItemToOrg marker counter items = do
(\n -> space <> literal "[@" <> literal (tshow n) <> literal "]")
counter
return $ hang (T.length marker + 1)
(literal marker <> cookie <> space) contents $$
(literal marker <> cookie <> space) (chomp contents) $$
if null items || endsWithPlain items
then cr
else blankline

View file

@ -32,6 +32,7 @@ import Text.Pandoc.Shared
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Shared
import Text.Pandoc.Walk
import Safe (lastMay)
type Refs = [([Inline], Target)]
@ -365,7 +366,7 @@ bulletListItemToRST :: PandocMonad m => [Block] -> RST m (Doc Text)
bulletListItemToRST items = do
contents <- blockListToRST items
return $ hang 3 "- " contents $$
if null items || endsWithPlain items
if null items || (endsWithPlain items && not (endsWithList items))
then cr
else blankline
@ -378,10 +379,16 @@ orderedListItemToRST marker items = do
contents <- blockListToRST items
let marker' = marker <> " "
return $ hang (T.length marker') (literal marker') contents $$
if null items || endsWithPlain items
if null items || (endsWithPlain items && not (endsWithList items))
then cr
else blankline
endsWithList :: [Block] -> Bool
endsWithList bs = case lastMay bs of
Just (BulletList{}) -> True
Just (OrderedList{}) -> True
_ -> False
-- | Convert definition list item (label, list of blocks) to RST.
definitionListItemToRST :: PandocMonad m => ([Inline], [[Block]]) -> RST m (Doc Text)
definitionListItemToRST (label, defs) = do

View file

@ -456,7 +456,9 @@ endsWithPlain :: [Block] -> Bool
endsWithPlain xs =
case lastMay xs of
Just Plain{} -> True
_ -> False
Just (BulletList is) -> maybe False endsWithPlain (lastMay is)
Just (OrderedList _ is) -> maybe False endsWithPlain (lastMay is)
_ -> False
-- | Convert the relevant components of a new-style table (with block
-- caption, row headers, row and column spans, and so on) to those of

View file

@ -206,7 +206,6 @@ Heres another:
- Fee
- Fie
- Foe
3. Third
Same thing but with paragraphs:

View file

@ -241,7 +241,6 @@ Here's another:
- Fee
- Fie
- Foe
3. Third
Same thing but with paragraphs: