git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Simplified and sped up str parser.
b6dc21bJohn MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+9−15
@@ -1381,8 +1381,14 @@ emph = fmap B.emph <$> nested
1381 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1381 (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd)
1382 where starStart = char '*' >> lookAhead nonspaceChar
1382 where starStart = char '*' >> lookAhead nonspaceChar
1383 starEnd = notFollowedBy' (() <$ strong) >> char '*'
1383 starEnd = notFollowedBy' (() <$ strong) >> char '*'
1384− ulStart = char '_' >> lookAhead nonspaceChar
1384+ ulStart = checkIntraword >> char '_' >> lookAhead nonspaceChar
1385 ulEnd = notFollowedBy' (() <$ strong) >> char '_'
1385 ulEnd = notFollowedBy' (() <$ strong) >> char '_'
1386+ checkIntraword = do
1387+ exts <- getOption readerExtensions
1388+ when (Ext_intraword_underscores `Set.member` exts) $ do
1389+ pos <- getPosition
1390+ lastStrPos <- stateLastStrPos <$> getState
1391+ guard $ lastStrPos /= Just pos
1386
1392
1387strong :: MarkdownParser (F Inlines)
1393strong :: MarkdownParser (F Inlines)
1388strong = fmap B.strong <$> nested
1394strong = fmap B.strong <$> nested
@@ -1421,23 +1427,11 @@ nonEndline = satisfy (/='\n')
1421
1427
1422str :: MarkdownParser (F Inlines)
1428str :: MarkdownParser (F Inlines)
1423str = do
1429str = do
1424− isSmart <- getOption readerSmart
1430+ result <- many1 alphaNum
1425− intrawordUnderscores <- option False $
1426− True <$ guardEnabled Ext_intraword_underscores
1427− a <- alphaNum
1428− as <- many $ alphaNum
1429− <|> (if intrawordUnderscores
1430− then try (char '_' >>~ lookAhead alphaNum)
1431− else mzero)
1432− <|> if isSmart
1433− then (try $ satisfy (\c -> c == '\'' || c == '\x2019') >>
1434− lookAhead alphaNum >> return '\x2019')
1435− -- for things like l'aide
1436− else mzero
1437 pos <- getPosition
1431 pos <- getPosition
1438 updateState $ \s -> s{ stateLastStrPos = Just pos }
1432 updateState $ \s -> s{ stateLastStrPos = Just pos }
1439− let result = a:as
1440 let spacesToNbr = map (\c -> if c == ' ' then '\160' else c)
1433 let spacesToNbr = map (\c -> if c == ' ' then '\160' else c)
1434+ isSmart <- getOption readerSmart
1441 if isSmart
1435 if isSmart
1442 then case likelyAbbrev result of
1436 then case likelyAbbrev result of
1443 [] -> return $ return $ B.str result
1437 [] -> return $ return $ B.str result