@@ -362,6 +362,14 @@ parseMarkdown = do
362362 optional titleBlock
363363 blocks <- parseBlocks
364364 st <- getState
365+ -- check for notes with no corresponding note references
366+ let notesUsed = stateNoteRefs st
367+ let notesDefined = M.keys (stateNotes' st)
368+ mapM_ (\n -> unless (n `Set.member` notesUsed) $ do
369+ -- lookup to get sourcepos
370+ case M.lookup n (stateNotes' st) of
371+ Just (pos, _) -> report (NoteDefinedButNotUsed n pos)
372+ Nothing -> error "The impossible happened.") notesDefined
365373 let doc = runF (do Pandoc _ bs <- B.doc <$> blocks
366374 meta <- stateMeta' st
367375 return $ Pandoc meta bs) st
@@ -469,12 +477,11 @@ noteBlock = try $ do
469477 let raw = unlines (first:rest) ++ "\n"
470478 optional blanklines
471479 parsed <- parseFromString' parseBlocks raw
472− let newnote = (ref, parsed)
473480 oldnotes <- stateNotes' <$> getState
474− case lookup ref oldnotes of
481+ case M.lookup ref oldnotes of
475482 Just _ -> logMessage $ DuplicateNoteReference ref pos
476483 Nothing -> return ()
477− updateState $ \s -> s { stateNotes' = newnote : oldnotes }
484+ updateState $ \s -> s { stateNotes' = M.insert ref (pos, parsed) oldnotes }
478485 return mempty
479486
480487--
@@ -1816,16 +1823,17 @@ note :: PandocMonad m => MarkdownParser m (F Inlines)
18161823note = try $ do
18171824 guardEnabled Ext_footnotes
18181825 ref <- noteMarker
1826+ updateState $ \st -> st{ stateNoteRefs = Set.insert ref (stateNoteRefs st) }
18191827 return $ do
18201828 notes <- asksF stateNotes'
1821− case lookup ref notes of
1829+ case M.lookup ref notes of
18221830 Nothing -> return $ B.str $ "[^" ++ ref ++ "]"
1823− Just contents -> do
1831+ Just (_pos, contents) -> do
18241832 st <- askF
18251833 -- process the note in a context that doesn't resolve
18261834 -- notes, to avoid infinite looping with notes inside
18271835 -- notes:
1828− let contents' = runF contents st{ stateNotes' = [] }
1836+ let contents' = runF contents st{ stateNotes' = M.empty }
18291837 return $ B.note contents'
18301838
18311839inlineNote :: PandocMonad m => MarkdownParser m (F Inlines)