summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-07 13:03:56 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-12-07 13:03:56 +0100
commit0e9c96d28a6303265a409c77385bb112156db134 (patch)
treebcb2268bd94884fb63664dced9bb5390c55b0aba /src
parent7fbfcb03d87feb369dcfabc1066e8f570ed471c8 (diff)
RST reader: print warnings when keys, substitition, notes not found.
Previously the parsers failed and we got raw text. Now we get a link with an empty URL, or empty inlines in the case of a note or substitution.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index e3d94d7b4..e05b6cba2 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -1131,8 +1131,14 @@ explicitLink = try $ do
(src',tit,attr) <- case reverse src of
'_':xs -> do
keyTable <- stateKeys <$> getState
- case M.lookup (toKey (reverse xs)) keyTable of
- Nothing -> fail "no corresponding key"
+ let key = toKey $ reverse xs
+ case M.lookup key keyTable of
+ Nothing -> do
+ pos <- getPosition
+ addWarning (Just pos) $
+ "Could not find reference for " ++
+ show key
+ return ("","",nullAttr)
Just ((s,t),a) -> return (s,t,a)
_ -> return (src, "", nullAttr)
return $ B.linkWith attr (escapeURI src') tit label''
@@ -1152,7 +1158,12 @@ referenceLink = try $ do
then mzero
else return (head anonKeys)
((src,tit), attr) <- case M.lookup key keyTable of
- Nothing -> fail "no corresponding key"
+ Nothing -> do
+ pos <- getPosition
+ addWarning (Just pos) $
+ "Could not find reference for " ++
+ show key
+ return (("",""),nullAttr)
Just val -> return val
-- if anonymous link, remove key so it won't be used again
when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
@@ -1176,8 +1187,13 @@ subst = try $ do
(_,ref) <- withRaw $ enclosed (char '|') (char '|') inline
state <- getState
let substTable = stateSubstitutions state
- case M.lookup (toKey $ stripFirstAndLast ref) substTable of
- Nothing -> fail "no corresponding key"
+ let key = toKey $ stripFirstAndLast ref
+ case M.lookup key substTable of
+ Nothing -> do
+ pos <- getPosition
+ addWarning (Just pos) $
+ "Could not find reference for " ++ show key
+ return mempty
Just target -> return target
note :: RSTParser Inlines
@@ -1188,7 +1204,11 @@ note = try $ do
state <- getState
let notes = stateNotes state
case lookup ref notes of
- Nothing -> fail "note not found"
+ Nothing -> do
+ pos <- getPosition
+ addWarning (Just pos) $
+ "Could not find note for " ++ show ref
+ return mempty
Just raw -> do
-- We temporarily empty the note list while parsing the note,
-- so that we don't get infinite loops with notes inside notes...