diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-01-25 23:28:57 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-01-25 23:30:27 -0800 |
commit | b6dc21bacf5cc4cb32ad0b91596ba5cc21eaeabb (patch) | |
tree | b99d9e76fbfa0d6f71f2a20714844f75b46bc459 /src | |
parent | c18fd7e6436243435d6b21934e943f54509b6e5f (diff) | |
download | pandoc-b6dc21bacf5cc4cb32ad0b91596ba5cc21eaeabb.tar.gz |
Markdown reader: Simplified and sped up str parser.
We no longer needed the smart quote complexity, because of
improvements to singleQuoteStart and singleQuoteEnd.
And we were able to move the check for intraword underscore
to the emphasis parser.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 75d1de67a..44cbbc676 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1381,8 +1381,14 @@ emph = fmap B.emph <$> nested (inlinesBetween starStart starEnd <|> inlinesBetween ulStart ulEnd) where starStart = char '*' >> lookAhead nonspaceChar starEnd = notFollowedBy' (() <$ strong) >> char '*' - ulStart = char '_' >> lookAhead nonspaceChar + ulStart = checkIntraword >> char '_' >> lookAhead nonspaceChar ulEnd = notFollowedBy' (() <$ strong) >> char '_' + checkIntraword = do + exts <- getOption readerExtensions + when (Ext_intraword_underscores `Set.member` exts) $ do + pos <- getPosition + lastStrPos <- stateLastStrPos <$> getState + guard $ lastStrPos /= Just pos strong :: MarkdownParser (F Inlines) strong = fmap B.strong <$> nested @@ -1421,23 +1427,11 @@ nonEndline = satisfy (/='\n') str :: MarkdownParser (F Inlines) str = do - isSmart <- getOption readerSmart - intrawordUnderscores <- option False $ - True <$ guardEnabled Ext_intraword_underscores - a <- alphaNum - as <- many $ alphaNum - <|> (if intrawordUnderscores - then try (char '_' >>~ lookAhead alphaNum) - else mzero) - <|> if isSmart - then (try $ satisfy (\c -> c == '\'' || c == '\x2019') >> - lookAhead alphaNum >> return '\x2019') - -- for things like l'aide - else mzero + result <- many1 alphaNum pos <- getPosition updateState $ \s -> s{ stateLastStrPos = Just pos } - let result = a:as let spacesToNbr = map (\c -> if c == ' ' then '\160' else c) + isSmart <- getOption readerSmart if isSmart then case likelyAbbrev result of [] -> return $ return $ B.str result |