Files
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

116 lines
2.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict'
var markdownLineEnding = require('../character/markdown-line-ending.js')
var markdownLineEndingOrSpace = require('../character/markdown-line-ending-or-space.js')
var normalizeIdentifier = require('../util/normalize-identifier.js')
var factoryDestination = require('./factory-destination.js')
var factoryLabel = require('./factory-label.js')
var factorySpace = require('./factory-space.js')
var factoryWhitespace = require('./factory-whitespace.js')
var factoryTitle = require('./factory-title.js')
var definition = {
name: 'definition',
tokenize: tokenizeDefinition
}
var titleConstruct = {
tokenize: tokenizeTitle,
partial: true
}
function tokenizeDefinition(effects, ok, nok) {
var self = this
var identifier
return start
function start(code) {
effects.enter('definition')
return factoryLabel.call(
self,
effects,
labelAfter,
nok,
'definitionLabel',
'definitionLabelMarker',
'definitionLabelString'
)(code)
}
function labelAfter(code) {
identifier = normalizeIdentifier(
self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1)
)
if (code === 58) {
effects.enter('definitionMarker')
effects.consume(code)
effects.exit('definitionMarker') // Note: blank lines cant exist in content.
return factoryWhitespace(
effects,
factoryDestination(
effects,
effects.attempt(
titleConstruct,
factorySpace(effects, after, 'whitespace'),
factorySpace(effects, after, 'whitespace')
),
nok,
'definitionDestination',
'definitionDestinationLiteral',
'definitionDestinationLiteralMarker',
'definitionDestinationRaw',
'definitionDestinationString'
)
)
}
return nok(code)
}
function after(code) {
if (code === null || markdownLineEnding(code)) {
effects.exit('definition')
if (self.parser.defined.indexOf(identifier) < 0) {
self.parser.defined.push(identifier)
}
return ok(code)
}
return nok(code)
}
}
function tokenizeTitle(effects, ok, nok) {
return start
function start(code) {
return markdownLineEndingOrSpace(code)
? factoryWhitespace(effects, before)(code)
: nok(code)
}
function before(code) {
if (code === 34 || code === 39 || code === 40) {
return factoryTitle(
effects,
factorySpace(effects, after, 'whitespace'),
nok,
'definitionTitle',
'definitionTitleMarker',
'definitionTitleString'
)(code)
}
return nok(code)
}
function after(code) {
return code === null || markdownLineEnding(code) ? ok(code) : nok(code)
}
}
module.exports = definition