Markdown reader: make attributes work with reference links.

Closes #9171.
This commit is contained in:
John MacFarlane
2023-11-05 21:27:03 -08:00
parent 6fdebc4afd
commit 76cd115d3b
2 changed files with 69 additions and 3 deletions
+4 -3
View File
@@ -1928,6 +1928,7 @@ referenceLink constructor (lab, raw) = do
<|>
try ((guardDisabled Ext_spaced_reference_links <|> spnl) >> reference)
when (raw' == "") $ guardEnabled Ext_shortcut_reference_links
!attr <- option nullAttr $ guardEnabled Ext_link_attributes >> attributes
let !labIsRef = raw' == "" || raw' == "[]"
let (exclam, rawsuffix) =
case T.uncons raw of
@@ -1956,11 +1957,11 @@ referenceLink constructor (lab, raw) = do
then do
headerKeys <- asksF stateHeaderKeys
case M.lookup key headerKeys of
Just ((src, tit), _) -> constructor nullAttr src tit <$> lab
Just ((src, tit), _) -> constructor attr src tit <$> lab
Nothing -> makeFallback
else makeFallback
Just ((src,tit), attr) ->
constructor attr src tit <$> lab
Just ((src,tit), defattr) ->
constructor (combineAttr attr defattr) src tit <$> lab
dropBrackets :: Text -> Text
dropBrackets = dropRB . dropLB
+65
View File
@@ -0,0 +1,65 @@
```
% pandoc -f markdown -t native
[link][link contents]{target="_blank"}
[link2](https://example.com){target="_blank"}
[link contents]: https://example.com
^D
[ Para
[ Link
( "" , [] , [ ( "target" , "_blank" ) ] )
[ Str "link" ]
( "https://example.com" , "" )
, SoftBreak
, Link
( "" , [] , [ ( "target" , "_blank" ) ] )
[ Str "link2" ]
( "https://example.com" , "" )
]
]
```
```
% pandoc -f markdown -t native
[link][link contents]{#id1 target="_blank"}
[link2](https://example.com){target="_blank"}
[link contents]: https://example.com {#id2 target="_nonblank"}
^D
[ Para
[ Link
( "id1" , [] , [ ( "target" , "_blank" ) ] )
[ Str "link" ]
( "https://example.com" , "" )
, SoftBreak
, Link
( "" , [] , [ ( "target" , "_blank" ) ] )
[ Str "link2" ]
( "https://example.com" , "" )
]
]
```
```
% pandoc -f markdown -t native
[link][link contents]{target="_blank"}
[link2](https://example.com){target="_blank"}
[link contents]: https://example.com {.foo}
^D
[ Para
[ Link
( "" , [ "foo" ] , [ ( "target" , "_blank" ) ] )
[ Str "link" ]
( "https://example.com" , "" )
, SoftBreak
, Link
( "" , [] , [ ( "target" , "_blank" ) ] )
[ Str "link2" ]
( "https://example.com" , "" )
]
]
```