git.iko.soy/typeable/pandoc
on master help sign in
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.

commitd9cdce4281254dce803e2fe21393eb3d40e2f875 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 13 Dec 2017, 10:20 (9 years ago) parent68edc9e
2 files changed+22−9
MANUAL.txt+6 src/Text/Pandoc/Readers/Markdown.hs+16−9
MANUAL.txt+6
@@ -2369,6 +2369,12 @@ document:
23692369The label can be any string of alphanumeric characters, underscores,
23702370or hyphens.
23712371
2372+Note: continuation paragraphs in example lists must always
2373+be indented four spaces, regardless of the length of the
2374+list marker. That is, example lists always behave as if the
2375+`four_space_rule` extension is set. This is because example
2376+labels tend to be long, and indenting content to the
2377+first non-space character after the label would be awkward.
23722378
23732379### Compact and loose lists ###
23742380
src/Text/Pandoc/Readers/Markdown.hs+16−9
@@ -863,14 +863,16 @@ listLineCommon = concat <$> manyTill
863863
864864-- parse raw text for one list item, excluding start marker and continuations
865865rawListItem :: PandocMonad m
866− => MarkdownParser m a
866+ => Bool -- four space rule
867+ -> MarkdownParser m a
867868 -> MarkdownParser m (String, Int)
868−rawListItem start = try $ do
869+rawListItem fourSpaceRule start = try $ do
869870 pos1 <- getPosition
870871 start
871872 pos2 <- getPosition
872− continuationIndent <- (4 <$ guardEnabled Ext_four_space_rule)
873− <|> return (sourceColumn pos2 - sourceColumn pos1)
873+ let continuationIndent = if fourSpaceRule
874+ then 4
875+ else (sourceColumn pos2 - sourceColumn pos1)
874876 first <- listLineCommon
875877 rest <- many (do notFollowedBy listStart
876878 notFollowedBy (() <$ codeBlockFenced)
@@ -914,10 +916,11 @@ notFollowedByHtmlCloser = do
914916 Nothing -> return ()
915917
916918listItem :: PandocMonad m
917− => MarkdownParser m a
919+ => Bool -- four-space rule
920+ -> MarkdownParser m a
918921 -> MarkdownParser m (F Blocks)
919−listItem start = try $ do
920− (first, continuationIndent) <- rawListItem start
922+listItem fourSpaceRule start = try $ do
923+ (first, continuationIndent) <- rawListItem fourSpaceRule start
921924 continuations <- many (listContinuation continuationIndent)
922925 -- parsing with ListItemState forces markers at beginning of lines to
923926 -- count as list item markers, even if not separated by blank space.
@@ -938,14 +941,18 @@ orderedList = try $ do
938941 delim `elem` [DefaultDelim, Period]) $
939942 guardEnabled Ext_fancy_lists
940943 when (style == Example) $ guardEnabled Ext_example_lists
941− items <- fmap sequence $ many1 $ listItem
944+ fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
945+ <|> return (style == Example)
946+ items <- fmap sequence $ many1 $ listItem fourSpaceRule
942947 (orderedListStart (Just (style, delim)))
943948 start' <- (start <$ guardEnabled Ext_startnum) <|> return 1
944949 return $ B.orderedListWith (start', style, delim) <$> fmap compactify items
945950
946951bulletList :: PandocMonad m => MarkdownParser m (F Blocks)
947952bulletList = do
948− items <- fmap sequence $ many1 $ listItem bulletListStart
953+ fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
954+ <|> return False
955+ items <- fmap sequence $ many1 $ listItem fourSpaceRule bulletListStart
949956 return $ B.bulletList <$> fmap compactify items
950957
951958-- definition lists