From 93b1dbfdac55aab11fa3db928de1bea09b4025e2 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 7 Feb 2022 09:20:33 -0800
Subject: [PATCH] HTML reader: give warnings and emit empty note...

when parsing `<a epub:type="noteref">` and the identifier
doesn't correspond to anything in the note table.

Previously we just silently skipped these cases.

See #7884.
---
 src/Text/Pandoc/Readers/HTML.hs | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index 6f7da15bf..d3b91c370 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -107,12 +107,18 @@ stripPrefix x = x
 replaceNotes :: PandocMonad m => [Block] -> TagParser m [Block]
 replaceNotes bs = do
   st <- getState
-  return $ walk (replaceNotes' (noteTable st)) bs
+  walkM (replaceNotes' (noteTable st)) bs
 
-replaceNotes' :: [(Text, Blocks)] -> Inline -> Inline
+replaceNotes' :: PandocMonad m
+              => [(Text, Blocks)] -> Inline -> TagParser m Inline
 replaceNotes' noteTbl (RawInline (Format "noteref") ref) =
-  maybe (Str "") (Note . B.toList) $ lookup ref noteTbl
-replaceNotes' _ x = x
+  maybe warnNotFound (pure . Note . B.toList) $ lookup ref noteTbl
+ where
+  warnNotFound = do
+    pos <- getPosition
+    logMessage $ ReferenceNotFound ref pos
+    pure (Note [])
+replaceNotes' _ x = pure x
 
 setInChapter :: PandocMonad m => HTMLParser m s a -> HTMLParser m s a
 setInChapter = local (\s -> s {inChapter = True})