Skip to content

Commit 76cd115

Browse files
committed
Markdown reader: make attributes work with reference links.
Closes #9171.
1 parent 6fdebc4 commit 76cd115

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

src/Text/Pandoc/Readers/Markdown.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@ referenceLink constructor (lab, raw) = do
19281928
<|>
19291929
try ((guardDisabled Ext_spaced_reference_links <|> spnl) >> reference)
19301930
when (raw' == "") $ guardEnabled Ext_shortcut_reference_links
1931+
!attr <- option nullAttr $ guardEnabled Ext_link_attributes >> attributes
19311932
let !labIsRef = raw' == "" || raw' == "[]"
19321933
let (exclam, rawsuffix) =
19331934
case T.uncons raw of
@@ -1956,11 +1957,11 @@ referenceLink constructor (lab, raw) = do
19561957
then do
19571958
headerKeys <- asksF stateHeaderKeys
19581959
case M.lookup key headerKeys of
1959-
Just ((src, tit), _) -> constructor nullAttr src tit <$> lab
1960+
Just ((src, tit), _) -> constructor attr src tit <$> lab
19601961
Nothing -> makeFallback
19611962
else makeFallback
1962-
Just ((src,tit), attr) ->
1963-
constructor attr src tit <$> lab
1963+
Just ((src,tit), defattr) ->
1964+
constructor (combineAttr attr defattr) src tit <$> lab
19641965

19651966
dropBrackets :: Text -> Text
19661967
dropBrackets = dropRB . dropLB

test/command/9171.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
```
2+
% pandoc -f markdown -t native
3+
[link][link contents]{target="_blank"}
4+
[link2](https://example.com){target="_blank"}
5+
6+
[link contents]: https://example.com
7+
^D
8+
[ Para
9+
[ Link
10+
( "" , [] , [ ( "target" , "_blank" ) ] )
11+
[ Str "link" ]
12+
( "https://example.com" , "" )
13+
, SoftBreak
14+
, Link
15+
( "" , [] , [ ( "target" , "_blank" ) ] )
16+
[ Str "link2" ]
17+
( "https://example.com" , "" )
18+
]
19+
]
20+
21+
```
22+
23+
```
24+
% pandoc -f markdown -t native
25+
[link][link contents]{#id1 target="_blank"}
26+
[link2](https://example.com){target="_blank"}
27+
28+
[link contents]: https://example.com {#id2 target="_nonblank"}
29+
^D
30+
[ Para
31+
[ Link
32+
( "id1" , [] , [ ( "target" , "_blank" ) ] )
33+
[ Str "link" ]
34+
( "https://example.com" , "" )
35+
, SoftBreak
36+
, Link
37+
( "" , [] , [ ( "target" , "_blank" ) ] )
38+
[ Str "link2" ]
39+
( "https://example.com" , "" )
40+
]
41+
]
42+
43+
```
44+
45+
```
46+
% pandoc -f markdown -t native
47+
[link][link contents]{target="_blank"}
48+
[link2](https://example.com){target="_blank"}
49+
50+
[link contents]: https://example.com {.foo}
51+
^D
52+
[ Para
53+
[ Link
54+
( "" , [ "foo" ] , [ ( "target" , "_blank" ) ] )
55+
[ Str "link" ]
56+
( "https://example.com" , "" )
57+
, SoftBreak
58+
, Link
59+
( "" , [] , [ ( "target" , "_blank" ) ] )
60+
[ Str "link2" ]
61+
( "https://example.com" , "" )
62+
]
63+
]
64+
65+
```

0 commit comments

Comments
 (0)