factory-whitespace.mjs 721 B

1234567891011121314151617181920212223242526272829303132
  1. export default whitespaceFactory
  2. import markdownLineEnding from '../character/markdown-line-ending.mjs'
  3. import markdownSpace from '../character/markdown-space.mjs'
  4. import types from '../constant/types.mjs'
  5. import spaceFactory from './factory-space.mjs'
  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 spaceFactory(
  19. effects,
  20. start,
  21. seen ? types.linePrefix : types.lineSuffix
  22. )(code)
  23. }
  24. return ok(code)
  25. }
  26. }