git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Fix rendering of tight sublists.

E.g. - foo - bar - baz Previously a spurious blank line was included before the last item. Closes #1050.

commit7f09c1834da9f87e7715f5c9dc52f4b730da8f3f authorJohn MacFarlane <jgm@berkeley.edu> dateSat 30 Nov 2013, 17:59 (13 years ago) parent7aa4d51
2 files changed+12−1
src/Text/Pandoc/Writers/Markdown.hs+8−1 tests/Tests/Writers/Markdown.hs+4
src/Text/Pandoc/Writers/Markdown.hs+8−1
@@ -555,7 +555,14 @@ bulletListItemToMarkdown opts items = do
555555 contents <- blockListToMarkdown opts items
556556 let sps = replicate (writerTabStop opts - 2) ' '
557557 let start = text ('-' : ' ' : sps)
558− return $ hang (writerTabStop opts) start $ contents <> cr
558+ -- remove trailing blank line if it is a tight list
559+ let contents' = case reverse items of
560+ (BulletList xs:_) | isTightList xs ->
561+ chomp contents <> cr
562+ (OrderedList _ xs:_) | isTightList xs ->
563+ chomp contents <> cr
564+ _ -> contents
565+ return $ hang (writerTabStop opts) start $ contents' <> cr
559566
560567-- | Convert ordered list item (a list of blocks) to markdown.
561568orderedListItemToMarkdown :: WriterOptions -- ^ options
tests/Tests/Writers/Markdown.hs+4
@@ -31,4 +31,8 @@ tests :: [Test]
3131tests = [ "indented code after list"
3232 =: (orderedList [ para "one" <> para "two" ] <> codeBlock "test")
3333 =?> "1. one\n\n two\n\n<!-- -->\n\n test"
34+ , "list with tight sublist"
35+ =: bulletList [ plain "foo" <> bulletList [ plain "bar" ],
36+ plain "baz" ]
37+ =?> "- foo\n - bar\n- baz\n"
3438 ]