aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-08 12:41:46 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-08 12:42:01 +0100
commitb6e7bfaf1d9fdec88aa81d7c7fa7431358706002 (patch)
treeebdf0d3336d5fbddb4532269db4ad96939adec27 /src
parent410991ec6e3615613db5d7f58f8ec8221373d5fd (diff)
downloadpandoc-b6e7bfaf1d9fdec88aa81d7c7fa7431358706002.tar.gz
Markdown writer: ensure space before list at top level.
Closes #3487.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 844df3345..782d0d085 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -822,29 +822,38 @@ blockListToMarkdown :: PandocMonad m
=> WriterOptions -- ^ Options
-> [Block] -- ^ List of block elements
-> MD m Doc
-blockListToMarkdown opts blocks =
+blockListToMarkdown opts blocks = do
+ inlist <- asks envInList
+ -- a) insert comment between list and indented code block, or the
+ -- code block will be treated as a list continuation paragraph
+ -- b) change Plain to Para unless it's followed by a RawBlock
+ -- or has a list as its parent (#3487)
+ let fixBlocks (b : CodeBlock attr x : rest)
+ | (not (isEnabled Ext_fenced_code_blocks opts) || attr == nullAttr)
+ && isListBlock b = b : commentSep : CodeBlock attr x :
+ fixBlocks rest
+ fixBlocks (b1@(BulletList _) : b2@(BulletList _) : bs) =
+ b1 : commentSep : fixBlocks (b2:bs)
+ fixBlocks (b1@(OrderedList _ _) : b2@(OrderedList _ _) : bs) =
+ b1 : commentSep : fixBlocks (b2:bs)
+ fixBlocks (b1@(DefinitionList _) : b2@(DefinitionList _) : bs) =
+ b1 : commentSep : fixBlocks (b2:bs)
+ fixBlocks (Plain ils : bs@(RawBlock{}:_)) =
+ Plain ils : fixBlocks bs
+ fixBlocks (Plain ils : bs) | inlist =
+ Plain ils : fixBlocks bs
+ fixBlocks (Plain ils : bs) =
+ Para ils : fixBlocks bs
+ fixBlocks (x : xs) = x : fixBlocks xs
+ fixBlocks [] = []
+ isListBlock (BulletList _) = True
+ isListBlock (OrderedList _ _) = True
+ isListBlock (DefinitionList _) = True
+ isListBlock _ = False
+ commentSep = if isEnabled Ext_raw_html opts
+ then RawBlock "html" "<!-- -->\n"
+ else RawBlock "markdown" "&nbsp;"
mapM (blockToMarkdown opts) (fixBlocks blocks) >>= return . cat
- -- insert comment between list and indented code block, or the
- -- code block will be treated as a list continuation paragraph
- where fixBlocks (b : CodeBlock attr x : rest)
- | (not (isEnabled Ext_fenced_code_blocks opts) || attr == nullAttr)
- && isListBlock b = b : commentSep : CodeBlock attr x :
- fixBlocks rest
- fixBlocks (b1@(BulletList _) : b2@(BulletList _) : bs) =
- b1 : commentSep : fixBlocks (b2:bs)
- fixBlocks (b1@(OrderedList _ _) : b2@(OrderedList _ _) : bs) =
- b1 : commentSep : fixBlocks (b2:bs)
- fixBlocks (b1@(DefinitionList _) : b2@(DefinitionList _) : bs) =
- b1 : commentSep : fixBlocks (b2:bs)
- fixBlocks (x : xs) = x : fixBlocks xs
- fixBlocks [] = []
- isListBlock (BulletList _) = True
- isListBlock (OrderedList _ _) = True
- isListBlock (DefinitionList _) = True
- isListBlock _ = False
- commentSep = if isEnabled Ext_raw_html opts
- then RawBlock "html" "<!-- -->\n"
- else RawBlock "markdown" "&nbsp;"
-- | Get reference for target; if none exists, create unique one and return.
-- Prefer label if possible; otherwise, generate a unique key.