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.
This commit is contained in:
John MacFarlane
2023-08-29 19:14:50 -07:00
parent 353177f9e7
commit cd3fcd5c0e
2 changed files with 15 additions and 4 deletions
+9 -4
View File
@@ -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
+6
View File
@@ -0,0 +1,6 @@
```
% pandoc -t native
![foo]
^D
[ Para [ Str "![foo]" ] ]
```