aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-08-29 19:14:50 -0700
committerJohn MacFarlane <[email protected]>2023-08-29 19:14:50 -0700
commitcd3fcd5c0e3382097bce81b9836a6a340ec9931b (patch)
treebebae25435f16128d6197f3bcc51afc90911864f /src
parent353177f9e7eadd60d66846325abd537b85fd46bb (diff)
Markdown reader: fix dropped `!` before nonexistent reference.
In e.g. `![foo]` the `!` would be silently dropped if `[foo]` wasn't a reference link label. Closes #9038.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index baf911b07..e2e30be25 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1931,15 +1931,20 @@ referenceLink constructor (lab, raw) = do
try ((guardDisabled Ext_spaced_reference_links <|> spnl) >> reference)
when (raw' == "") $ guardEnabled Ext_shortcut_reference_links
let !labIsRef = raw' == "" || raw' == "[]"
- let !key = toKey $ if labIsRef then raw else raw'
+ let (rawprefix, rawsuffix) =
+ case T.uncons raw of
+ Just ('!', x) -> ("!", x)
+ _ -> ("", raw)
+ let !key = toKey $ if labIsRef then rawsuffix else raw'
parsedRaw <- parseFromString' inlines raw'
- fallback <- parseFromString' inlines $ dropBrackets raw
+ fallback <- parseFromString' inlines $ dropBrackets rawsuffix
implicitHeaderRefs <- option False $
True <$ guardEnabled Ext_implicit_header_references
let makeFallback = do
parsedRaw' <- parsedRaw
fallback' <- fallback
- return $ B.str "[" <> fallback' <> B.str "]" <>
+ return $ rawprefix <>
+ B.str "[" <> fallback' <> B.str "]" <>
(if sp && not (T.null raw) then B.space else mempty) <>
parsedRaw'
return $ do
@@ -2014,7 +2019,7 @@ image = try $ do
"" -> B.imageWith attr' (T.pack $ addExtension (T.unpack src)
$ T.unpack defaultExt)
_ -> B.imageWith attr' src
- regLink constructor lab <|> referenceLink constructor (lab,raw)
+ regLink constructor lab <|> referenceLink constructor (lab, "!" <> raw)
note :: PandocMonad m => MarkdownParser m (F Inlines)
note = try $ do