This commit is contained in:
44
node_modules/mdast-util-to-hast/lib/revert.js
generated
vendored
Normal file
44
node_modules/mdast-util-to-hast/lib/revert.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = revert
|
||||
|
||||
var u = require('unist-builder')
|
||||
var all = require('./all')
|
||||
|
||||
// Return the content of a reference without definition as markdown.
|
||||
function revert(h, node) {
|
||||
var subtype = node.referenceType
|
||||
var suffix = ']'
|
||||
var contents
|
||||
var head
|
||||
var tail
|
||||
|
||||
if (subtype === 'collapsed') {
|
||||
suffix += '[]'
|
||||
} else if (subtype === 'full') {
|
||||
suffix += '[' + (node.label || node.identifier) + ']'
|
||||
}
|
||||
|
||||
if (node.type === 'imageReference') {
|
||||
return u('text', '![' + node.alt + suffix)
|
||||
}
|
||||
|
||||
contents = all(h, node)
|
||||
head = contents[0]
|
||||
|
||||
if (head && head.type === 'text') {
|
||||
head.value = '[' + head.value
|
||||
} else {
|
||||
contents.unshift(u('text', '['))
|
||||
}
|
||||
|
||||
tail = contents[contents.length - 1]
|
||||
|
||||
if (tail && tail.type === 'text') {
|
||||
tail.value += suffix
|
||||
} else {
|
||||
contents.push(u('text', suffix))
|
||||
}
|
||||
|
||||
return contents
|
||||
}
|
||||
Reference in New Issue
Block a user