git.iko.soy/typeable/pandoc
on master help sign in
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

commit25bbe134cb6e498330f669492ab427c7799cfe0d authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 1 Sep 2007, 20:26 (19 years ago) parent76d462c
1 file changed+16−14
src/Text/Pandoc/Readers/Markdown.hs+16−14
src/Text/Pandoc/Readers/Markdown.hs+16−14
@@ -143,22 +143,25 @@ parseMarkdown = do
143143 (title, author, date) <- option ([],[],"") titleBlock
144144 -- go through once just to get list of reference keys
145145 refs <- manyTill (referenceKey <|> (lineClump >>= return . LineClump)) eof
146− let keys = map (\(KeyBlock label target) -> (label, target)) $
146+ let keys = map (\(KeyBlock label target) -> (label, target)) $
147147 filter isKeyBlock refs
148− let rawlines = map (\(LineClump ln) -> ln) $ filter isLineClump refs
149− setInput $ concat rawlines -- with keys stripped out
148+ -- strip out keys
149+ setInput $ concatMap (\(LineClump ln) -> ln) $ filter isLineClump refs
150150 updateState (\state -> state { stateKeys = keys })
151− -- now go through for notes (which may contain references - hence 2nd pass)
152− refs <- manyTill (noteBlock <|> (lineClump >>= return . LineClump)) eof
153− let notes = map (\(NoteBlock label blocks) -> (label, blocks)) $
154− filter isNoteBlock refs
155− let rawlines = map (\(LineClump ln) -> ln) $ filter isLineClump refs
156− -- go through a 3rd time, with note blocks and keys stripped out
157− setInput $ concat rawlines
158− updateState (\state -> state { stateNotes = notes })
151+ st <- getState
152+ if stateStrict st
153+ then return ()
154+ else do -- go through for notes (which may contain refs - hence 2nd pass)
155+ refs' <- manyTill (noteBlock <|>
156+ (lineClump >>= return . LineClump)) eof
157+ let notes = map (\(NoteBlock label blocks) -> (label, blocks)) $
158+ filter isNoteBlock refs'
159+ updateState (\state -> state { stateNotes = notes })
160+ setInput $ concatMap (\(LineClump ln) -> ln) $
161+ filter isLineClump refs'
162+ -- go through again, with note blocks and keys stripped out
159163 blocks <- parseBlocks
160− let blocks' = filter (/= Null) blocks
161− return $ Pandoc (Meta title author date) blocks'
164+ return $ Pandoc (Meta title author date) $ filter (/= Null) blocks
162165
163166--
164167-- initial pass for references and notes
@@ -198,7 +201,6 @@ rawLine = do
198201rawLines = many1 rawLine >>= return . concat
199202
200203noteBlock = try $ do
201− failIfStrict
202204 ref <- noteMarker
203205 char ':'
204206 optional blankline