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 = try $ do
result <- many1 inline
if all isHtmlOrBlank result
then fail "treat as raw HTML"
else return ()
newline
blanklines <|> do st <- getState
if stateStrict st
then lookAhead (blockQuote <|> header) >> return ""
else pzero
return $ Para $ normalizeSpaces result
result <- liftM normalizeSpaces $ many1 inline
guard $ not . all isHtmlOrBlank $ result
option (Plain result) $ try $ do
newline
blanklines <|>
(getState >>= guard . stateStrict >>
lookAhead (blockQuote <|> header) >> return "")
return $ Para result
plain :: GenParser Char ParserState Block
plain = many1 inline >>~ spaces >>= return . Plain . normalizeSpaces