aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-04 12:01:09 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-04 12:01:09 -0800
commitef806f6a99dcb99b16282082e76d629f24dcafa8 (patch)
treec68c07cb6a98f4e31885bd3184dd80e3ac4a70a6 /src/Text
parent4e381e787aa0c94ee129c4364b4b8e4e699cac68 (diff)
downloadpandoc-ef806f6a99dcb99b16282082e76d629f24dcafa8.tar.gz
Markdown reader: Warn about duplicate link references.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Parsing.hs1
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs13
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 3aa013fdc..629814e4d 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -134,6 +134,7 @@ module Text.Pandoc.Parsing ( (>>~),
getState,
setState,
updateState,
+ SourcePos,
getPosition,
setPosition,
sourceColumn,
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index b687faae7..16141369a 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -241,8 +241,15 @@ parseMarkdown = do
$ B.setDate (runF date st)
$ B.doc $ runF blocks st
+addWarning :: Maybe SourcePos -> String -> MarkdownParser ()
+addWarning mbpos msg =
+ updateState $ \st -> st{
+ stateWarnings = (msg ++ maybe "" (\pos -> " " ++ show pos) mbpos) :
+ stateWarnings st }
+
referenceKey :: MarkdownParser (F Blocks)
referenceKey = try $ do
+ pos <- getPosition
skipNonindentSpaces
(_,raw) <- reference
char ':'
@@ -262,7 +269,11 @@ referenceKey = try $ do
let target = (escapeURI $ trimr src, tit)
st <- getState
let oldkeys = stateKeys st
- updateState $ \s -> s { stateKeys = M.insert (toKey raw) target oldkeys }
+ let key = toKey raw
+ case M.lookup key oldkeys of
+ Just _ -> addWarning (Just pos) $ "Duplicate link reference `" ++ raw ++ "'"
+ Nothing -> return ()
+ updateState $ \s -> s { stateKeys = M.insert key target oldkeys }
return $ return mempty
referenceTitle :: MarkdownParser String