summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-13 10:20:57 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-13 10:20:57 -0800
commitd9cdce4281254dce803e2fe21393eb3d40e2f875 (patch)
treefdc2433d48e10f674d9ea47737e11d283014f786
parent68edc9efbfd3af5583201ceb5f60e96d34aead1d (diff)
Markdown reader: always use four space rule for example lists.
It would be awkward to indent example list contents to the first non-space character after the label, since example list labels are often long. Thanks to Bernhard Fisseni for the suggestion.
-rw-r--r--MANUAL.txt6
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs25
2 files changed, 22 insertions, 9 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 9fd0e3381..fb2d494f6 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -2369,6 +2369,12 @@ document:
The label can be any string of alphanumeric characters, underscores,
or hyphens.
+Note: continuation paragraphs in example lists must always
+be indented four spaces, regardless of the length of the
+list marker. That is, example lists always behave as if the
+`four_space_rule` extension is set. This is because example
+labels tend to be long, and indenting content to the
+first non-space character after the label would be awkward.
### Compact and loose lists ###
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 68f810abe..3b6dcbcb9 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -863,14 +863,16 @@ listLineCommon = concat <$> manyTill
-- parse raw text for one list item, excluding start marker and continuations
rawListItem :: PandocMonad m
- => MarkdownParser m a
+ => Bool -- four space rule
+ -> MarkdownParser m a
-> MarkdownParser m (String, Int)
-rawListItem start = try $ do
+rawListItem fourSpaceRule start = try $ do
pos1 <- getPosition
start
pos2 <- getPosition
- continuationIndent <- (4 <$ guardEnabled Ext_four_space_rule)
- <|> return (sourceColumn pos2 - sourceColumn pos1)
+ let continuationIndent = if fourSpaceRule
+ then 4
+ else (sourceColumn pos2 - sourceColumn pos1)
first <- listLineCommon
rest <- many (do notFollowedBy listStart
notFollowedBy (() <$ codeBlockFenced)
@@ -914,10 +916,11 @@ notFollowedByHtmlCloser = do
Nothing -> return ()
listItem :: PandocMonad m
- => MarkdownParser m a
+ => Bool -- four-space rule
+ -> MarkdownParser m a
-> MarkdownParser m (F Blocks)
-listItem start = try $ do
- (first, continuationIndent) <- rawListItem start
+listItem fourSpaceRule start = try $ do
+ (first, continuationIndent) <- rawListItem fourSpaceRule start
continuations <- many (listContinuation continuationIndent)
-- parsing with ListItemState forces markers at beginning of lines to
-- count as list item markers, even if not separated by blank space.
@@ -938,14 +941,18 @@ orderedList = try $ do
delim `elem` [DefaultDelim, Period]) $
guardEnabled Ext_fancy_lists
when (style == Example) $ guardEnabled Ext_example_lists
- items <- fmap sequence $ many1 $ listItem
+ fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
+ <|> return (style == Example)
+ items <- fmap sequence $ many1 $ listItem fourSpaceRule
(orderedListStart (Just (style, delim)))
start' <- (start <$ guardEnabled Ext_startnum) <|> return 1
return $ B.orderedListWith (start', style, delim) <$> fmap compactify items
bulletList :: PandocMonad m => MarkdownParser m (F Blocks)
bulletList = do
- items <- fmap sequence $ many1 $ listItem bulletListStart
+ fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
+ <|> return False
+ items <- fmap sequence $ many1 $ listItem fourSpaceRule bulletListStart
return $ B.bulletList <$> fmap compactify items
-- definition lists