diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-09-01 20:26:40 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-09-01 20:26:40 +0000 |
commit | 25bbe134cb6e498330f669492ab427c7799cfe0d (patch) | |
tree | 1ee3bf16bae0ccbf4735714040796a4c59b0a6f6 | |
parent | 76d462c1cd3e7b25e09d7d7efb23ff4a017344f2 (diff) | |
download | pandoc-25bbe134cb6e498330f669492ab427c7799cfe0d.tar.gz |
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
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 30 |
1 files changed, 16 insertions, 14 deletions
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 |