list-item.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module.exports = listItem
  2. var repeat = require('repeat-string')
  3. var checkBullet = require('../util/check-bullet')
  4. var checkListItemIndent = require('../util/check-list-item-indent')
  5. var flow = require('../util/container-flow')
  6. var indentLines = require('../util/indent-lines')
  7. function listItem(node, parent, context) {
  8. var bullet = checkBullet(context)
  9. var listItemIndent = checkListItemIndent(context)
  10. var size
  11. var value
  12. var exit
  13. if (parent && parent.ordered) {
  14. bullet =
  15. (parent.start > -1 ? parent.start : 1) +
  16. (context.options.incrementListMarker === false
  17. ? 0
  18. : parent.children.indexOf(node)) +
  19. '.'
  20. }
  21. size = bullet.length + 1
  22. if (
  23. listItemIndent === 'tab' ||
  24. (listItemIndent === 'mixed' && ((parent && parent.spread) || node.spread))
  25. ) {
  26. size = Math.ceil(size / 4) * 4
  27. }
  28. exit = context.enter('listItem')
  29. value = indentLines(flow(node, context), map)
  30. exit()
  31. return value
  32. function map(line, index, blank) {
  33. if (index) {
  34. return (blank ? '' : repeat(' ', size)) + line
  35. }
  36. return (blank ? bullet : bullet + repeat(' ', size - bullet.length)) + line
  37. }
  38. }