mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-12 18:45:58 +00:00
Markdown parser performance improvement.
Do a quick lookahead to make sure what follows looks like a setext header before parsing any Inlines. This gives a 15% performance boost in one benchmark. Many thanks to knieriem for finding the problem (in peg-markdown): https://github.com/jgm/peg-markdown/issues/issue/3
This commit is contained in:
@@ -320,6 +320,9 @@ atxClosing = try $ skipMany (char '#') >> blanklines
|
||||
|
||||
setextHeader :: GenParser Char ParserState Block
|
||||
setextHeader = try $ do
|
||||
-- This lookahead prevents us from wasting time parsing Inlines
|
||||
-- unless necessary -- it gives a significant performance boost.
|
||||
lookAhead $ anyLine >> many1 (oneOf setextHChars) >> blankline
|
||||
text <- many1Till inline newline
|
||||
underlineChar <- oneOf setextHChars
|
||||
many (char underlineChar)
|
||||
|
||||
Reference in New Issue
Block a user