|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import {factoryDestination} from 'micromark-factory-destination' |
|
import {factoryLabel} from 'micromark-factory-label' |
|
import {factorySpace} from 'micromark-factory-space' |
|
import {factoryTitle} from 'micromark-factory-title' |
|
import {factoryWhitespace} from 'micromark-factory-whitespace' |
|
import { |
|
markdownLineEnding, |
|
markdownLineEndingOrSpace, |
|
markdownSpace |
|
} from 'micromark-util-character' |
|
import {normalizeIdentifier} from 'micromark-util-normalize-identifier' |
|
|
|
export const definition = { |
|
name: 'definition', |
|
tokenize: tokenizeDefinition |
|
} |
|
|
|
|
|
const titleBefore = { |
|
tokenize: tokenizeTitleBefore, |
|
partial: true |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function tokenizeDefinition(effects, ok, nok) { |
|
const self = this |
|
|
|
let identifier |
|
return start |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function start(code) { |
|
|
|
|
|
|
|
effects.enter('definition') |
|
return before(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function before(code) { |
|
|
|
|
|
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') |
|
return markerAfter |
|
} |
|
return nok(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function markerAfter(code) { |
|
|
|
return markdownLineEndingOrSpace(code) |
|
? factoryWhitespace(effects, destinationBefore)(code) |
|
: destinationBefore(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function destinationBefore(code) { |
|
return factoryDestination( |
|
effects, |
|
destinationAfter, |
|
|
|
nok, |
|
'definitionDestination', |
|
'definitionDestinationLiteral', |
|
'definitionDestinationLiteralMarker', |
|
'definitionDestinationRaw', |
|
'definitionDestinationString' |
|
)(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function destinationAfter(code) { |
|
return effects.attempt(titleBefore, after, after)(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function after(code) { |
|
return markdownSpace(code) |
|
? factorySpace(effects, afterWhitespace, 'whitespace')(code) |
|
: afterWhitespace(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function afterWhitespace(code) { |
|
if (code === null || markdownLineEnding(code)) { |
|
effects.exit('definition') |
|
|
|
|
|
|
|
|
|
self.parser.defined.push(identifier) |
|
|
|
|
|
|
|
|
|
return ok(code) |
|
} |
|
return nok(code) |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function tokenizeTitleBefore(effects, ok, nok) { |
|
return titleBefore |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function titleBefore(code) { |
|
return markdownLineEndingOrSpace(code) |
|
? factoryWhitespace(effects, beforeMarker)(code) |
|
: nok(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function beforeMarker(code) { |
|
return factoryTitle( |
|
effects, |
|
titleAfter, |
|
nok, |
|
'definitionTitle', |
|
'definitionTitleMarker', |
|
'definitionTitleString' |
|
)(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function titleAfter(code) { |
|
return markdownSpace(code) |
|
? factorySpace(effects, titleAfterOptionalWhitespace, 'whitespace')(code) |
|
: titleAfterOptionalWhitespace(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function titleAfterOptionalWhitespace(code) { |
|
return code === null || markdownLineEnding(code) ? ok(code) : nok(code) |
|
} |
|
} |
|
|