git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: ensure space before list at top level.

Closes #3487.

commitb6e7bfaf1d9fdec88aa81d7c7fa7431358706002 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 8 Mar 2017, 12:41 (10 years ago) parent410991e
2 files changed+44−22
src/Text/Pandoc/Writers/Markdown.hs+31−22 test/command/3487.md+13
src/Text/Pandoc/Writers/Markdown.hs+31−22
@@ -822,29 +822,38 @@ blockListToMarkdown :: PandocMonad m
822822 => WriterOptions -- ^ Options
823823 -> [Block] -- ^ List of block elements
824824 -> MD m Doc
825−blockListToMarkdown opts blocks =
825+blockListToMarkdown opts blocks = do
826+ inlist <- asks envInList
827+ -- a) insert comment between list and indented code block, or the
828+ -- code block will be treated as a list continuation paragraph
829+ -- b) change Plain to Para unless it's followed by a RawBlock
830+ -- or has a list as its parent (#3487)
831+ let fixBlocks (b : CodeBlock attr x : rest)
832+ | (not (isEnabled Ext_fenced_code_blocks opts) || attr == nullAttr)
833+ && isListBlock b = b : commentSep : CodeBlock attr x :
834+ fixBlocks rest
835+ fixBlocks (b1@(BulletList _) : b2@(BulletList _) : bs) =
836+ b1 : commentSep : fixBlocks (b2:bs)
837+ fixBlocks (b1@(OrderedList _ _) : b2@(OrderedList _ _) : bs) =
838+ b1 : commentSep : fixBlocks (b2:bs)
839+ fixBlocks (b1@(DefinitionList _) : b2@(DefinitionList _) : bs) =
840+ b1 : commentSep : fixBlocks (b2:bs)
841+ fixBlocks (Plain ils : bs@(RawBlock{}:_)) =
842+ Plain ils : fixBlocks bs
843+ fixBlocks (Plain ils : bs) | inlist =
844+ Plain ils : fixBlocks bs
845+ fixBlocks (Plain ils : bs) =
846+ Para ils : fixBlocks bs
847+ fixBlocks (x : xs) = x : fixBlocks xs
848+ fixBlocks [] = []
849+ isListBlock (BulletList _) = True
850+ isListBlock (OrderedList _ _) = True
851+ isListBlock (DefinitionList _) = True
852+ isListBlock _ = False
853+ commentSep = if isEnabled Ext_raw_html opts
854+ then RawBlock "html" "<!-- -->\n"
855+ else RawBlock "markdown" "&nbsp;"
826856 mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . cat
827− -- insert comment between list and indented code block, or the
828− -- code block will be treated as a list continuation paragraph
829− where fixBlocks (b : CodeBlock attr x : rest)
830− | (not (isEnabled Ext_fenced_code_blocks opts) || attr == nullAttr)
831− && isListBlock b = b : commentSep : CodeBlock attr x :
832− fixBlocks rest
833− fixBlocks (b1@(BulletList _) : b2@(BulletList _) : bs) =
834− b1 : commentSep : fixBlocks (b2:bs)
835− fixBlocks (b1@(OrderedList _ _) : b2@(OrderedList _ _) : bs) =
836− b1 : commentSep : fixBlocks (b2:bs)
837− fixBlocks (b1@(DefinitionList _) : b2@(DefinitionList _) : bs) =
838− b1 : commentSep : fixBlocks (b2:bs)
839− fixBlocks (x : xs) = x : fixBlocks xs
840− fixBlocks [] = []
841− isListBlock (BulletList _) = True
842− isListBlock (OrderedList _ _) = True
843− isListBlock (DefinitionList _) = True
844− isListBlock _ = False
845− commentSep = if isEnabled Ext_raw_html opts
846− then RawBlock "html" "<!-- -->\n"
847− else RawBlock "markdown" "&nbsp;"
848857
849858-- | Get reference for target; if none exists, create unique one and return.
850859-- Prefer label if possible; otherwise, generate a unique key.
test/command/3487.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -f html -t markdown
3+Some text
4+<ul>
5+<li>element</li>
6+</ul>
7+^D
8+Some text
9+
10+- element
11+
12+
13+```