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.
This commit is contained in:
John MacFarlane 2022-02-07 09:20:33 -08:00
parent 4864761ad8
commit 93b1dbfdac

View file

@ -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})