micromark-extension-directive/lib/factory-name.js
2020-12-08 18:11:22 +01:00

30 lines
606 B
JavaScript

'use strict'
module.exports = createName
var asciiAlpha = require('micromark/dist/character/ascii-alpha')
var asciiAlphanumeric = require('micromark/dist/character/ascii-alphanumeric')
function createName(effects, ok, nok, nameType) {
return start
function start(code) {
if (asciiAlpha(code)) {
effects.enter(nameType)
effects.consume(code)
return name
}
return nok(code)
}
function name(code) {
if (code === 45 /* `-` */ || asciiAlphanumeric(code)) {
effects.consume(code)
return name
}
effects.exit(nameType)
return ok(code)
}
}