Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commonmark spec compliance: full and compact reference fallbacks #21

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/failsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ var all = require('./all')
function failsafe(h, node, definition) {
var subtype = node.referenceType

if (subtype !== 'collapsed' && subtype !== 'full' && !definition) {
if (!definition) {
if (node.type === 'imageReference') {
return u('text', '![' + node.alt + ']')
if (subtype === 'collapsed') {
return u('text', '![' + node.alt + '][]')
} else if (subtype === 'full') {
return u('text', '![' + node.alt + '][' + node.identifier + ']')
} else {
return u('text', '![' + node.alt + ']')
}
}

return [u('text', '[')].concat(all(h, node), u('text', ']'))
if (subtype === 'collapsed') {
return [u('text', '[')].concat(all(h, node), u('text', '][]'))
} else if (subtype === 'full') {
return [u('text', '[')].concat(all(h, node),
u('text', '][' + node.identifier + ']'))
} else {
return [u('text', '[')].concat(all(h, node), u('text', ']'))
}
}
}
28 changes: 4 additions & 24 deletions test/image-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,8 @@ test('ImageReference', function(t) {
alt: 'golf'
})
),
u(
'element',
{
tagName: 'img',
properties: {
src: '',
alt: 'golf'
}
},
[]
),
'should not fall back on full `imageReference`s'
u('text', '![golf][foxtrot]'),
'should fall back on full `imageReference`s'
)

t.deepEqual(
Expand All @@ -46,18 +36,8 @@ test('ImageReference', function(t) {
alt: 'india'
})
),
u(
'element',
{
tagName: 'img',
properties: {
src: '',
alt: 'india'
}
},
[]
),
'should not fall back on collapsed `imageReference`s'
u('text', '![india][]'),
'should fall back on collapsed `imageReference`s'
)

t.deepEqual(
Expand Down
26 changes: 4 additions & 22 deletions test/link-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ test('LinkReference', function(t) {
[u('text', 'echo')]
)
),
u(
'element',
{
tagName: 'a',
properties: {
href: ''
}
},
[u('text', 'echo')]
),
'should not fall back on full `linkReference`s'
[u('text', '['), u('text', 'echo'), u('text', '][delta]')],
'should fall back on full `linkReference`s'
)

t.deepEqual(
Expand All @@ -54,17 +45,8 @@ test('LinkReference', function(t) {
[u('text', 'hotel')]
)
),
u(
'element',
{
tagName: 'a',
properties: {
href: ''
}
},
[u('text', 'hotel')]
),
'should not fall back on collapsed `linkReference`s'
[u('text', '['), u('text', 'hotel'), u('text', '][]')],
'should fall back on collapsed `linkReference`s'
)

t.deepEqual(
Expand Down