Markdown Reader: Fix inline code in lists (#6284)

Closes #6284.

Previously inline code containing list markers was sometimes parsed incorrectly.
This commit is contained in:
Nikolay Yakimov
2020-04-16 02:20:01 +03:00
committed by GitHub
parent b64ece76cb
commit 83c1ce1d77
2 changed files with 58 additions and 6 deletions
+11 -6
View File
@@ -1517,12 +1517,17 @@ code :: PandocMonad m => MarkdownParser m (F Inlines)
code = try $ do
starts <- many1 (char '`')
skipSpaces
result <- (trim . T.concat) <$>
manyTill (notFollowedBy (inList >> listStart) >>
(many1Char (noneOf "`\n") <|> many1Char (char '`') <|>
(char '\n' >> notFollowedBy' blankline >> return " ")))
(try (skipSpaces >> count (length starts) (char '`') >>
notFollowedBy (char '`')))
result <- trim . T.concat
<$> manyTill
( many1Char (noneOf "`\n")
<|> many1Char (char '`')
<|> (char '\n'
>> notFollowedBy (inList >> listStart)
>> notFollowedBy' blankline
>> return " "))
(try $ skipSpaces
>> count (length starts) (char '`')
>> notFollowedBy (char '`'))
rawattr <-
(Left <$> try (guardEnabled Ext_raw_attribute >> rawAttribute))
<|>
+47
View File
@@ -171,6 +171,53 @@ tests = [ testGroup "inline code"
=?> para (code "*" <> space <> str "{.haskell" <> space <>
str ".special" <> space <> str "x=\"7\"}")
]
, testGroup "inline code in lists (regression tests for #6284)" $
let lists = [("ordered", "1. ", ol), ("bullet", "- ", ul)]
ol = orderedListWith (1, Decimal, Period)
ul = bulletList
items =
[ ("in text" , ["If `(1) x`, then `2`"], [text "If " <> code "(1) x" <> text ", then " <> code "2"])
, ("at start" , ["`#. x`" ], [code "#. x" ])
, ("at start" , ["`- x`" ], [code "- x" ])
, ("after literal backticks", ["`x``#. x`" ], [code "x``#. x" ])
, ("after literal backticks", ["`x``- x`" ], [code "x``- x" ])
]
lis = ["`text","y","x`"]
lis' = ["text","y","x"]
bldLsts w lsts txts
= let (res, res', f) =
foldr (\((_, _, lt), lc) (acc, tacc, t) ->
if lt [] == t []
then (acc, lc : tacc, lt)
else (join t tacc acc, [lc], lt))
(mempty, [], mconcat)
(zip lsts (map text txts))
join t tacc acc = case tacc of
[] -> acc
[x] -> t [plain x] <> acc
xs -> t (map w xs) <> acc
in join f res' res
in ["code with list marker "<>mp<>" in " <> ln <> " list" =:
T.intercalate "\n" (map (lstr <>) istrs) =?> lbld (map plain iblds)
| (ln, lstr, lbld) <- lists, (mp, istrs, iblds) <- items]
<> [ "lists with newlines in backticks" =:
T.intercalate "\n" (zipWith (\i (_, lt, _) -> lt <> i) lis lsts)
=?> bldLsts plain lsts lis
| lsts <- [ [i, j, k] | i <- lists, j <- lists, k <- lists]
]
<> [ "lists with newlines and indent in backticks" =:
T.intercalate ("\n" <> T.replicate 4 " ") (zipWith (\i (_, lt, _) -> lt <> i) lis lsts)
=?> let (_, _, f) = head lsts
in f [plain $ code $ T.intercalate (T.replicate 5 " ") $ head lis' : zipWith (\i (_, lt, _) -> lt <> i) (tail lis') (tail lsts)]
| lsts <- [ [i, j, k] | i <- lists, j <- lists, k <- lists]
]
<> [ "lists with blank lines and indent in backticks" =:
T.intercalate ("\n\n" <> T.replicate 4 " ") (zipWith (\i (_, lt, _) -> lt <> i) lis lsts)
<> "\n"
=?> let (_, _, f) = head lsts
in f . pure $ (para . text $ head lis) <> bldLsts para (tail lsts) (tail lis)
| lsts <- [ [i, j, k] | i <- lists, j <- lists, k <- lists]
]
, testGroup "emph and strong"
[ "two strongs in emph" =:
"***a**b **c**d*" =?> para (emph (strong (str "a") <> str "b" <> space