blank-line.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict'
  2. // A line containing no characters, or a line containing only spaces (U+0020) or
  3. // tabs (U+0009), is called a blank line.
  4. // See <https://spec.commonmark.org/0.29/#blank-line>.
  5. var reBlankLine = /^[ \t]*(\n|$)/
  6. // Note that though blank lines play a special role in lists to determine
  7. // whether the list is tight or loose
  8. // (<https://spec.commonmark.org/0.29/#blank-lines>), it’s done by the list
  9. // tokenizer and this blank line tokenizer does not have to be responsible for
  10. // that.
  11. // Therefore, configs such as `blankLine.notInList` do not have to be set here.
  12. module.exports = blankLine
  13. function blankLine(eat, value, silent) {
  14. var match
  15. var subvalue = ''
  16. var index = 0
  17. var length = value.length
  18. while (index < length) {
  19. match = reBlankLine.exec(value.slice(index))
  20. if (match == null) {
  21. break
  22. }
  23. index += match[0].length
  24. subvalue += match[0]
  25. }
  26. if (subvalue === '') {
  27. return
  28. }
  29. /* istanbul ignore if - never used (yet) */
  30. if (silent) {
  31. return true
  32. }
  33. eat(subvalue)
  34. }