Files
30-seconds-of-code/node_modules/mdast-util-to-hast/lib/handlers/footnote.js
2019-08-20 15:52:05 +02:00

37 lines
755 B
JavaScript

'use strict'
module.exports = footnote
var footnoteReference = require('./footnote-reference')
function footnote(h, node) {
var identifiers = []
var identifier = 1
var footnotes = h.footnotes
var length = footnotes.length
var index = -1
while (++index < length) {
identifiers[index] = footnotes[index].identifier
}
while (identifiers.indexOf(String(identifier)) !== -1) {
identifier++
}
identifier = String(identifier)
footnotes.push({
type: 'footnoteDefinition',
identifier: identifier,
children: [{type: 'paragraph', children: node.children}],
position: node.position
})
return footnoteReference(h, {
type: 'footnoteReference',
identifier: identifier,
position: node.position
})
}