@@ -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)]
874− updateState $ \st -> st{ stateNotes = newnotes }
880+ updateState $ \st -> st{ stateNotes = newnotes }
875 return $ Note contents
881 return $ Note contents