git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: always use four space rule for example lists.
d9cdce4John MacFarlane
MANUAL.txt+6
@@ -2369,6 +2369,12 @@ document:
2369The label can be any string of alphanumeric characters, underscores,
2369The label can be any string of alphanumeric characters, underscores,
2370or hyphens.
2370or hyphens.
2371
2371
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.
2372
2378
2373### Compact and loose lists ###
2379### Compact and loose lists ###
2374
2380
src/Text/Pandoc/Readers/Markdown.hs+16−9
@@ -863,14 +863,16 @@ listLineCommon = concat <$> manyTill
863
863
864-- parse raw text for one list item, excluding start marker and continuations
864-- parse raw text for one list item, excluding start marker and continuations
865rawListItem :: PandocMonad m
865rawListItem :: PandocMonad m
866+ => Bool -- four space rule
866− => MarkdownParser m a
867+ -> MarkdownParser m a
867 -> MarkdownParser m (String, Int)
868 -> MarkdownParser m (String, Int)
868−rawListItem start = try $ do
869+rawListItem fourSpaceRule start = try $ do
869 pos1 <- getPosition
870 pos1 <- getPosition
870 start
871 start
871 pos2 <- getPosition
872 pos2 <- getPosition
872− continuationIndent <- (4 <$ guardEnabled Ext_four_space_rule)
873+ let continuationIndent = if fourSpaceRule
874+ then 4
873− <|> return (sourceColumn pos2 - sourceColumn pos1)
875+ else (sourceColumn pos2 - sourceColumn pos1)
874 first <- listLineCommon
876 first <- listLineCommon
875 rest <- many (do notFollowedBy listStart
877 rest <- many (do notFollowedBy listStart
876 notFollowedBy (() <$ codeBlockFenced)
878 notFollowedBy (() <$ codeBlockFenced)
@@ -914,10 +916,11 @@ notFollowedByHtmlCloser = do
914 Nothing -> return ()
916 Nothing -> return ()
915
917
916listItem :: PandocMonad m
918listItem :: PandocMonad m
919+ => Bool -- four-space rule
917− => MarkdownParser m a
920+ -> MarkdownParser m a
918 -> MarkdownParser m (F Blocks)
921 -> MarkdownParser m (F Blocks)
919−listItem start = try $ do
922+listItem fourSpaceRule start = try $ do
920− (first, continuationIndent) <- rawListItem start
923+ (first, continuationIndent) <- rawListItem fourSpaceRule start
921 continuations <- many (listContinuation continuationIndent)
924 continuations <- many (listContinuation continuationIndent)
922 -- parsing with ListItemState forces markers at beginning of lines to
925 -- parsing with ListItemState forces markers at beginning of lines to
923 -- count as list item markers, even if not separated by blank space.
926 -- count as list item markers, even if not separated by blank space.
@@ -938,14 +941,18 @@ orderedList = try $ do
938 delim `elem` [DefaultDelim, Period]) $
941 delim `elem` [DefaultDelim, Period]) $
939 guardEnabled Ext_fancy_lists
942 guardEnabled Ext_fancy_lists
940 when (style == Example) $ guardEnabled Ext_example_lists
943 when (style == Example) $ guardEnabled Ext_example_lists
944+ fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
945+ <|> return (style == Example)
941− items <- fmap sequence $ many1 $ listItem
946+ items <- fmap sequence $ many1 $ listItem fourSpaceRule
942 (orderedListStart (Just (style, delim)))
947 (orderedListStart (Just (style, delim)))
943 start' <- (start <$ guardEnabled Ext_startnum) <|> return 1
948 start' <- (start <$ guardEnabled Ext_startnum) <|> return 1
944 return $ B.orderedListWith (start', style, delim) <$> fmap compactify items
949 return $ B.orderedListWith (start', style, delim) <$> fmap compactify items
945
950
946bulletList :: PandocMonad m => MarkdownParser m (F Blocks)
951bulletList :: PandocMonad m => MarkdownParser m (F Blocks)
947bulletList = do
952bulletList = do
953+ fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule)
954+ <|> return False
948− items <- fmap sequence $ many1 $ listItem bulletListStart
955+ items <- fmap sequence $ many1 $ listItem fourSpaceRule bulletListStart
949 return $ B.bulletList <$> fmap compactify items
956 return $ B.bulletList <$> fmap compactify items
950
957
951-- definition lists
958-- definition lists