Skip to content

Commit

Permalink
HTML reader: give warnings and emit empty note...
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Feb 7, 2022
1 parent 4864761 commit 93b1dbf
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Text/Pandoc/Readers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit 93b1dbf

Please sign in to comment.