aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-11-30 17:59:28 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2013-11-30 17:59:28 -0800
commit7f09c1834da9f87e7715f5c9dc52f4b730da8f3f (patch)
treedd9b1dcf97b94b45e3cd182af60f56ec2bd6a731
parent7aa4d519686af1416eaf3b380f8584ab89569c41 (diff)
downloadpandoc-7f09c1834da9f87e7715f5c9dc52f4b730da8f3f.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs9
-rw-r--r--tests/Tests/Writers/Markdown.hs4
2 files changed, 12 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index eefcd547a..60d474263 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -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
diff --git a/tests/Tests/Writers/Markdown.hs b/tests/Tests/Writers/Markdown.hs
index 99b85dfb7..c2a8f5903 100644
--- a/tests/Tests/Writers/Markdown.hs
+++ b/tests/Tests/Writers/Markdown.hs
@@ -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"
]