@@ -161,18 +161,24 @@ titleBlock = try (do
161161 return (title, author, date))
162162
163163parseMarkdown = do
164− updateState (\state -> state { stateParseRaw = True }) -- parse raw HTML: markdown allows it
164+ updateState (\state -> state { stateParseRaw = True }) -- markdown allows raw HTML
165165 (title, author, date) <- option ([],[],"") titleBlock
166166 -- go through once just to get list of reference keys
167− refs <- manyTill (noteBlock <|> referenceKey <|> (do l <- lineClump
168− return (LineClump l))) eof
167+ refs <- manyTill (referenceKey <|> (do l <- lineClump
168+ return (LineClump l))) eof
169169 let keys = map (\(KeyBlock label target) -> (label, target)) $
170170 filter isKeyBlock refs
171+ let rawlines = map (\(LineClump ln) -> ln) $ filter isLineClump refs
172+ setInput $ concat rawlines -- with keys stripped out
173+ updateState (\state -> state { stateKeys = keys })
174+ -- now go through for notes
175+ refs <- manyTill (noteBlock <|> (do l <- lineClump
176+ return (LineClump l))) eof
171177 let notes = map (\(NoteBlock label blocks) -> (label, blocks)) $
172178 filter isNoteBlock refs
173179 let rawlines = map (\(LineClump ln) -> ln) $ filter isLineClump refs
174180 setInput $ concat rawlines -- with note blocks and keys stripped out
175− updateState (\state -> state { stateKeys = keys, stateNotes = notes })
181+ updateState (\state -> state { stateNotes = notes })
176182 blocks <- parseBlocks -- go through again, for real
177183 let blocks' = filter (/= Null) blocks
178184 return (Pandoc (Meta title author date) blocks')