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

53 lines
1.0 KiB
JavaScript

'use strict'
module.exports = generateFootnotes
var thematicBreak = require('./handlers/thematic-break')
var list = require('./handlers/list')
var wrap = require('./wrap')
function generateFootnotes(h) {
var footnotes = h.footnotes
var length = footnotes.length
var index = -1
var listItems = []
var def
if (!length) {
return null
}
while (++index < length) {
def = footnotes[index]
listItems[index] = {
type: 'listItem',
data: {hProperties: {id: 'fn-' + def.identifier}},
children: def.children.concat({
type: 'link',
url: '#fnref-' + def.identifier,
data: {hProperties: {className: ['footnote-backref']}},
children: [{type: 'text', value: '↩'}]
}),
position: def.position
}
}
return h(
null,
'div',
{className: ['footnotes']},
wrap(
[
thematicBreak(h),
list(h, {
type: 'list',
ordered: true,
children: listItems
})
],
true
)
)
}