Skip to content

Commit

Permalink
Markdown writer: Fix rendering of tight sublists.
Browse files Browse the repository at this point in the history
E.g.

    - foo
        - bar
    - baz

Previously a spurious blank line was included before the last item.
Closes #1050.
  • Loading branch information
jgm committed Dec 1, 2013
1 parent 7aa4d51 commit 7f09c18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Text/Pandoc/Writers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,14 @@ bulletListItemToMarkdown opts items = do
contents <- blockListToMarkdown opts items
let sps = replicate (writerTabStop opts - 2) ' '
let start = text ('-' : ' ' : sps)
return $ hang (writerTabStop opts) start $ contents <> cr
-- remove trailing blank line if it is a tight list
let contents' = case reverse items of
(BulletList xs:_) | isTightList xs ->
chomp contents <> cr
(OrderedList _ xs:_) | isTightList xs ->
chomp contents <> cr
_ -> contents
return $ hang (writerTabStop opts) start $ contents' <> cr

-- | Convert ordered list item (a list of blocks) to markdown.
orderedListItemToMarkdown :: WriterOptions -- ^ options
Expand Down
4 changes: 4 additions & 0 deletions tests/Tests/Writers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ tests :: [Test]
tests = [ "indented code after list"
=: (orderedList [ para "one" <> para "two" ] <> codeBlock "test")
=?> "1. one\n\n two\n\n<!-- -->\n\n test"
, "list with tight sublist"
=: bulletList [ plain "foo" <> bulletList [ plain "bar" ],
plain "baz" ]
=?> "- foo\n - bar\n- baz\n"
]

0 comments on commit 7f09c18

Please sign in to comment.