Markdown reader: Rewrote para parser for better efficiency.

This change avoids repeated parsing of inline lists for 'plain'
blocks.
This commit is contained in:
John MacFarlane 2010-12-10 10:47:46 -08:00
parent bb609a85e3
commit ee0a0953de

View file

@ -650,16 +650,14 @@ isHtmlOrBlank _ = False
para :: GenParser Char ParserState Block para :: GenParser Char ParserState Block
para = try $ do para = try $ do
result <- many1 inline result <- liftM normalizeSpaces $ many1 inline
if all isHtmlOrBlank result guard $ not . all isHtmlOrBlank $ result
then fail "treat as raw HTML" option (Plain result) $ try $ do
else return ()
newline newline
blanklines <|> do st <- getState blanklines <|>
if stateStrict st (getState >>= guard . stateStrict >>
then lookAhead (blockQuote <|> header) >> return "" lookAhead (blockQuote <|> header) >> return "")
else pzero return $ Para result
return $ Para $ normalizeSpaces result
plain :: GenParser Char ParserState Block plain :: GenParser Char ParserState Block
plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces