footnote.js 755 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict'
  2. module.exports = footnote
  3. var footnoteReference = require('./footnote-reference')
  4. function footnote(h, node) {
  5. var identifiers = []
  6. var identifier = 1
  7. var footnotes = h.footnotes
  8. var length = footnotes.length
  9. var index = -1
  10. while (++index < length) {
  11. identifiers[index] = footnotes[index].identifier
  12. }
  13. while (identifiers.indexOf(String(identifier)) !== -1) {
  14. identifier++
  15. }
  16. identifier = String(identifier)
  17. footnotes.push({
  18. type: 'footnoteDefinition',
  19. identifier: identifier,
  20. children: [{type: 'paragraph', children: node.children}],
  21. position: node.position
  22. })
  23. return footnoteReference(h, {
  24. type: 'footnoteReference',
  25. identifier: identifier,
  26. position: node.position
  27. })
  28. }