git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Fixed regression with intraword underscores.

Closes #1121.

commit83d4c2733c2406654b485326530fc5922bf9a924 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 10 Jul 2014, 14:51 (12 years ago) parentee522be
1 file changed+16−10
src/Text/Pandoc/Readers/Markdown.hs+16−10
src/Text/Pandoc/Readers/Markdown.hs+16−10
@@ -1450,36 +1450,42 @@ enclosure c = do
14501450 1 -> one c mempty
14511451 _ -> return (return $ B.str cs)
14521452
1453+ender :: Char -> Int -> MarkdownParser ()
1454+ender c n = try $ do
1455+ count n (char c)
1456+ guard (c == '*')
1457+ <|> guardDisabled Ext_intraword_underscores
1458+ <|> notFollowedBy alphaNum
1459+
14531460-- Parse inlines til you hit one c or a sequence of two cs.
14541461-- If one c, emit emph and then parse two.
14551462-- If two cs, emit strong and then parse one.
14561463-- Otherwise, emit ccc then the results.
14571464three :: Char -> MarkdownParser (F Inlines)
14581465three c = do
1459− contents <- mconcat <$> many (notFollowedBy (char c) >> inline)
1460− (try (string [c,c,c]) >> return ((B.strong . B.emph) <$> contents))
1461− <|> (try (string [c,c]) >> one c (B.strong <$> contents))
1462− <|> (char c >> two c (B.emph <$> contents))
1466+ contents <- mconcat <$> many (notFollowedBy (ender c 1) >> inline)
1467+ (ender c 3 >> return ((B.strong . B.emph) <$> contents))
1468+ <|> (ender c 2 >> one c (B.strong <$> contents))
1469+ <|> (ender c 1 >> two c (B.emph <$> contents))
14631470 <|> return (return (B.str [c,c,c]) <> contents)
14641471
14651472-- Parse inlines til you hit two c's, and emit strong.
14661473-- If you never do hit two cs, emit ** plus inlines parsed.
14671474two :: Char -> F Inlines -> MarkdownParser (F Inlines)
14681475two c prefix' = do
1469− let ender = try $ string [c,c]
1470− contents <- mconcat <$> many (try $ notFollowedBy ender >> inline)
1471− (ender >> return (B.strong <$> (prefix' <> contents)))
1476+ contents <- mconcat <$> many (try $ notFollowedBy (ender c 2) >> inline)
1477+ (ender c 2 >> return (B.strong <$> (prefix' <> contents)))
14721478 <|> return (return (B.str [c,c]) <> (prefix' <> contents))
14731479
14741480-- Parse inlines til you hit a c, and emit emph.
14751481-- If you never hit a c, emit * plus inlines parsed.
14761482one :: Char -> F Inlines -> MarkdownParser (F Inlines)
14771483one c prefix' = do
1478− contents <- mconcat <$> many ( (notFollowedBy (char c) >> inline)
1484+ contents <- mconcat <$> many ( (notFollowedBy (ender c 1) >> inline)
14791485 <|> try (string [c,c] >>
1480− notFollowedBy (char c) >>
1486+ notFollowedBy (ender c 1) >>
14811487 two c mempty) )
1482− (char c >> return (B.emph <$> (prefix' <> contents)))
1488+ (ender c 1 >> return (B.emph <$> (prefix' <> contents)))
14831489 <|> return (return (B.str [c]) <> (prefix' <> contents))
14841490
14851491strongOrEmph :: MarkdownParser (F Inlines)