Markdown: Allow a citation or reference link to be parsed after a !.

Closes #8254.
This commit is contained in:
John MacFarlane
2023-08-29 19:25:30 -07:00
parent cd3fcd5c0e
commit 7dca09d03a
2 changed files with 29 additions and 6 deletions
+9 -6
View File
@@ -1931,20 +1931,23 @@ 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 (rawprefix, rawsuffix) =
let (exclam, rawsuffix) =
case T.uncons raw of
Just ('!', x) -> ("!", x)
_ -> ("", raw)
Just ('!', rest) -> (True, rest)
_ -> (False, raw)
let !key = toKey $ if labIsRef then rawsuffix else raw'
parsedRaw <- parseFromString' inlines raw'
fallback <- parseFromString' inlines $ dropBrackets rawsuffix
fallback <- parseFromString' inlines $ if exclam
then rawsuffix
else dropBrackets rawsuffix
implicitHeaderRefs <- option False $
True <$ guardEnabled Ext_implicit_header_references
let makeFallback = do
parsedRaw' <- parsedRaw
fallback' <- fallback
return $ rawprefix <>
B.str "[" <> fallback' <> B.str "]" <>
return $ (if exclam
then "!" <> fallback'
else B.str "[" <> fallback' <> B.str "]") <>
(if sp && not (T.null raw) then B.space else mempty) <>
parsedRaw'
return $ do
+20
View File
@@ -0,0 +1,20 @@
```
% pandoc -t native
Wow![@legras_michel_2010]
^D
[ Para
[ Str "Wow!"
, Cite
[ Citation
{ citationId = "legras_michel_2010"
, citationPrefix = []
, citationSuffix = []
, citationMode = NormalCitation
, citationNoteNum = 2
, citationHash = 0
}
]
[ Str "[@legras_michel_2010]" ]
]
]
```