footer.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict'
  2. module.exports = generateFootnotes
  3. var thematicBreak = require('./handlers/thematic-break')
  4. var list = require('./handlers/list')
  5. var wrap = require('./wrap')
  6. function generateFootnotes(h) {
  7. var footnotes = h.footnotes
  8. var length = footnotes.length
  9. var index = -1
  10. var listItems = []
  11. var def
  12. if (!length) {
  13. return null
  14. }
  15. while (++index < length) {
  16. def = footnotes[index]
  17. listItems[index] = {
  18. type: 'listItem',
  19. data: {hProperties: {id: 'fn-' + def.identifier}},
  20. children: def.children.concat({
  21. type: 'link',
  22. url: '#fnref-' + def.identifier,
  23. data: {hProperties: {className: ['footnote-backref']}},
  24. children: [{type: 'text', value: '↩'}]
  25. }),
  26. position: def.position
  27. }
  28. }
  29. return h(
  30. null,
  31. 'div',
  32. {className: ['footnotes']},
  33. wrap(
  34. [
  35. thematicBreak(h),
  36. list(h, {
  37. type: 'list',
  38. ordered: true,
  39. children: listItems
  40. })
  41. ],
  42. true
  43. )
  44. )
  45. }