Skip to content

Commit 42004b0

Browse files
wooormrubys
andcommitted
Fix reverting full references if label exists
Closes GH-22. Related to GH-20. Related to syntax-tree/mdast#23. Related to remarkjs/remark#346. Co-authored-by: Sam Ruby <[email protected]>
1 parent 9c1f065 commit 42004b0

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/revert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function revert(h, node) {
1616
if (subtype === 'collapsed') {
1717
suffix += '[]'
1818
} else if (subtype === 'full') {
19-
suffix += '[' + node.identifier + ']'
19+
suffix += '[' + (node.label || node.identifier) + ']'
2020
}
2121

2222
if (node.type === 'imageReference') {

test/image-reference.js

+13
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,18 @@ test('ImageReference', function(t) {
6666
'should transform `imageReference`s to `img`s'
6767
)
6868

69+
t.deepEqual(
70+
to(
71+
u('imageReference', {
72+
identifier: 'tango',
73+
label: 'Tango',
74+
referenceType: 'full',
75+
alt: 'uniform'
76+
})
77+
),
78+
u('text', '![uniform][Tango]'),
79+
'should fall back on the label on a full `imageReference` (GH-22)'
80+
)
81+
6982
t.end()
7083
})

test/link-reference.js

+13
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,18 @@ test('LinkReference', function(t) {
6969
'should transform `linkReference`s to `a`s'
7070
)
7171

72+
t.deepEqual(
73+
to(
74+
u('linkReference', {
75+
identifier: 'oscar',
76+
label: 'Oscar',
77+
referenceType: 'full',
78+
alt: 'papa'
79+
})
80+
),
81+
u('text', '![papa][Oscar]'),
82+
'should fall back on the label on a full `linkReference` (GH-22)'
83+
)
84+
7285
t.end()
7386
})

0 commit comments

Comments
 (0)