You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
528 B
29 lines
528 B
export default spaceFactory |
|
|
|
import markdownSpace from '../character/markdown-space.mjs' |
|
|
|
function spaceFactory(effects, ok, type, max) { |
|
var limit = max ? max - 1 : Infinity |
|
var size = 0 |
|
|
|
return start |
|
|
|
function start(code) { |
|
if (markdownSpace(code)) { |
|
effects.enter(type) |
|
return prefix(code) |
|
} |
|
|
|
return ok(code) |
|
} |
|
|
|
function prefix(code) { |
|
if (markdownSpace(code) && size++ < limit) { |
|
effects.consume(code) |
|
return prefix |
|
} |
|
|
|
effects.exit(type) |
|
return ok(code) |
|
} |
|
}
|
|
|