git.iko.soy/typeable/pandoc
on master help sign in
Disallow notes within notes in reST and markdown.
b42c48eJohn MacFarlane
src/Tests/Readers/Markdown.hs+3
@@ -47,6 +47,9 @@ tests = [ testGroup "inline code"
47 , "indent followed by newline and indented text" =:
47 , "indent followed by newline and indented text" =:
48 "[^1]\n\n[^1]: my note\n \n in note\n"
48 "[^1]\n\n[^1]: my note\n \n in note\n"
49 =?> para (note (para "my note" +++ para "in note"))
49 =?> para (note (para "my note" +++ para "in note"))
50+ , "recursive note" =:
51+ "[^1]\n\n[^1]: See [^1]\n"
52+ =?> para (note (para "See [^1]"))
50 ]
53 ]
51 , testGroup "lhs"
54 , testGroup "lhs"
52 [ test (readMarkdown defaultParserState{stateLiterateHaskell = True})
55 [ test (readMarkdown defaultParserState{stateLiterateHaskell = True})
src/Text/Pandoc/Readers/Markdown.hs+8−1
@@ -1187,7 +1187,14 @@ note = try $ do
1187 let notes = stateNotes state
1187 let notes = stateNotes state
1188 case lookup ref notes of
1188 case lookup ref notes of
1189 Nothing -> fail "note not found"
1189 Nothing -> fail "note not found"
1190+ Just raw -> do
1191+ -- We temporarily empty the note list while parsing the note,
1192+ -- so that we don't get infinite loops with notes inside notes...
1193+ -- Note references inside other notes do not work.
1194+ updateState $ \st -> st{ stateNotes = [] }
1190− Just raw -> liftM Note $ parseFromString parseBlocks raw
1195+ contents <- parseFromString parseBlocks raw
1196+ updateState $ \st -> st{ stateNotes = notes }
1197+ return $ Note contents
1191
1198
1192inlineNote :: GenParser Char ParserState Inline
1199inlineNote :: GenParser Char ParserState Inline
1193inlineNote = try $ do
1200inlineNote = try $ do
src/Text/Pandoc/Readers/RST.hs+11−5
@@ -866,10 +866,16 @@ note = try $ do
866 case lookup ref notes of
866 case lookup ref notes of
867 Nothing -> fail "note not found"
867 Nothing -> fail "note not found"
868 Just raw -> do
868 Just raw -> do
869+ -- We temporarily empty the note list while parsing the note,
870+ -- so that we don't get infinite loops with notes inside notes...
871+ -- Note references inside other notes are allowed in reST, but
872+ -- not yet in this implementation.
873+ updateState $ \st -> st{ stateNotes = [] }
869 contents <- parseFromString parseBlocks raw
874 contents <- parseFromString parseBlocks raw
870− when (ref == "*" || ref == "#") $ do -- auto-numbered
875+ let newnotes = if (ref == "*" || ref == "#") -- auto-numbered
871− -- delete the note so the next auto-numbered note
876+ -- delete the note so the next auto-numbered note
872− -- doesn't get the same contents:
877+ -- doesn't get the same contents:
873− let newnotes = deleteFirstsBy (==) notes [(ref,raw)]
878+ then deleteFirstsBy (==) notes [(ref,raw)]
879+ else notes
874− updateState $ \st -> st{ stateNotes = newnotes }
880+ updateState $ \st -> st{ stateNotes = newnotes }
875 return $ Note contents
881 return $ Note contents