Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eded45e

Browse files
wooormrubys
andcommittedNov 11, 2018
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 eded45e

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-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

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

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

0 commit comments

Comments
 (0)