factory-space.mjs 528 B

1234567891011121314151617181920212223242526272829
  1. export default spaceFactory
  2. import markdownSpace from '../character/markdown-space.mjs'
  3. function spaceFactory(effects, ok, type, max) {
  4. var limit = max ? max - 1 : Infinity
  5. var size = 0
  6. return start
  7. function start(code) {
  8. if (markdownSpace(code)) {
  9. effects.enter(type)
  10. return prefix(code)
  11. }
  12. return ok(code)
  13. }
  14. function prefix(code) {
  15. if (markdownSpace(code) && size++ < limit) {
  16. effects.consume(code)
  17. return prefix
  18. }
  19. effects.exit(type)
  20. return ok(code)
  21. }
  22. }