Skip to content

Commit

Permalink
Fix reverting full references if label exists
Browse files Browse the repository at this point in the history
Closes GH-22.
Related to GH-20.
Related to syntax-tree/mdast#23.
Related to remarkjs/remark#346.

Co-authored-by: Sam Ruby <rubys@intertwingly.net>
  • Loading branch information
wooorm and rubys committed Nov 11, 2018
1 parent 9c1f065 commit 42004b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/revert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function revert(h, node) {
if (subtype === 'collapsed') {
suffix += '[]'
} else if (subtype === 'full') {
suffix += '[' + node.identifier + ']'
suffix += '[' + (node.label || node.identifier) + ']'
}

if (node.type === 'imageReference') {
Expand Down
13 changes: 13 additions & 0 deletions test/image-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,18 @@ test('ImageReference', function(t) {
'should transform `imageReference`s to `img`s'
)

t.deepEqual(
to(
u('imageReference', {
identifier: 'tango',
label: 'Tango',
referenceType: 'full',
alt: 'uniform'
})
),
u('text', '![uniform][Tango]'),
'should fall back on the label on a full `imageReference` (GH-22)'
)

t.end()
})
13 changes: 13 additions & 0 deletions test/link-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,18 @@ test('LinkReference', function(t) {
'should transform `linkReference`s to `a`s'
)

t.deepEqual(
to(
u('linkReference', {
identifier: 'oscar',
label: 'Oscar',
referenceType: 'full',
alt: 'papa'
})
),
u('text', '![papa][Oscar]'),
'should fall back on the label on a full `linkReference` (GH-22)'
)

t.end()
})

0 comments on commit 42004b0

Please sign in to comment.