factory-whitespace.js 745 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict'
  2. var markdownLineEnding = require('../character/markdown-line-ending.js')
  3. var markdownSpace = require('../character/markdown-space.js')
  4. var types = require('../constant/types.js')
  5. var factorySpace = require('./factory-space.js')
  6. function whitespaceFactory(effects, ok) {
  7. var seen
  8. return start
  9. function start(code) {
  10. if (markdownLineEnding(code)) {
  11. effects.enter(types.lineEnding)
  12. effects.consume(code)
  13. effects.exit(types.lineEnding)
  14. seen = true
  15. return start
  16. }
  17. if (markdownSpace(code)) {
  18. return factorySpace(
  19. effects,
  20. start,
  21. seen ? types.linePrefix : types.lineSuffix
  22. )(code)
  23. }
  24. return ok(code)
  25. }
  26. }
  27. module.exports = whitespaceFactory