all.js 693 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict'
  2. module.exports = all
  3. var trim = require('trim')
  4. var one = require('./one')
  5. function all(h, parent) {
  6. var nodes = parent.children || []
  7. var length = nodes.length
  8. var values = []
  9. var index = -1
  10. var result
  11. var head
  12. while (++index < length) {
  13. result = one(h, nodes[index], parent)
  14. if (result) {
  15. if (index && nodes[index - 1].type === 'break') {
  16. if (result.value) {
  17. result.value = trim.left(result.value)
  18. }
  19. head = result.children && result.children[0]
  20. if (head && head.value) {
  21. head.value = trim.left(head.value)
  22. }
  23. }
  24. values = values.concat(result)
  25. }
  26. }
  27. return values
  28. }