From 25bbe134cb6e498330f669492ab427c7799cfe0d Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 1 Sep 2007 20:26:40 +0000 Subject: Skip notes parsing if running in strict mode. (This yields a nice speed improvement in strict mode.) git-svn-id: https://pandoc.googlecode.com/svn/trunk@983 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 1583e5e7b..82c61985a 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -143,22 +143,25 @@ parseMarkdown = do (title, author, date) <- option ([],[],"") titleBlock -- go through once just to get list of reference keys refs <- manyTill (referenceKey <|> (lineClump >>= return . LineClump)) eof - let keys = map (\(KeyBlock label target) -> (label, target)) $ + let keys = map (\(KeyBlock label target) -> (label, target)) $ filter isKeyBlock refs - let rawlines = map (\(LineClump ln) -> ln) $ filter isLineClump refs - setInput $ concat rawlines -- with keys stripped out + -- strip out keys + setInput $ concatMap (\(LineClump ln) -> ln) $ filter isLineClump refs updateState (\state -> state { stateKeys = keys }) - -- now go through for notes (which may contain references - hence 2nd pass) - refs <- manyTill (noteBlock <|> (lineClump >>= return . LineClump)) eof - let notes = map (\(NoteBlock label blocks) -> (label, blocks)) $ - filter isNoteBlock refs - let rawlines = map (\(LineClump ln) -> ln) $ filter isLineClump refs - -- go through a 3rd time, with note blocks and keys stripped out - setInput $ concat rawlines - updateState (\state -> state { stateNotes = notes }) + st <- getState + if stateStrict st + then return () + else do -- go through for notes (which may contain refs - hence 2nd pass) + refs' <- manyTill (noteBlock <|> + (lineClump >>= return . LineClump)) eof + let notes = map (\(NoteBlock label blocks) -> (label, blocks)) $ + filter isNoteBlock refs' + updateState (\state -> state { stateNotes = notes }) + setInput $ concatMap (\(LineClump ln) -> ln) $ + filter isLineClump refs' + -- go through again, with note blocks and keys stripped out blocks <- parseBlocks - let blocks' = filter (/= Null) blocks - return $ Pandoc (Meta title author date) blocks' + return $ Pandoc (Meta title author date) $ filter (/= Null) blocks -- -- initial pass for references and notes @@ -198,7 +201,6 @@ rawLine = do rawLines = many1 rawLine >>= return . concat noteBlock = try $ do - failIfStrict ref <- noteMarker char ':' optional blankline -- cgit v1.2.3