aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs30
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