Files
coopgo/node_modules/micromark/dist/tokenize/factory-title.js
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

76 lines
1.6 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 factorySpace = require('./factory-space.js')
function titleFactory(effects, ok, nok, type, markerType, stringType) {
var marker
return start
function start(code) {
effects.enter(type)
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
marker = code === 40 ? 41 : code
return atFirstTitleBreak
}
function atFirstTitleBreak(code) {
if (code === marker) {
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
effects.exit(type)
return ok
}
effects.enter(stringType)
return atTitleBreak(code)
}
function atTitleBreak(code) {
if (code === marker) {
effects.exit(stringType)
return atFirstTitleBreak(marker)
}
if (code === null) {
return nok(code)
} // Note: blank lines cant exist in content.
if (markdownLineEnding(code)) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return factorySpace(effects, atTitleBreak, 'linePrefix')
}
effects.enter('chunkString', {
contentType: 'string'
})
return title(code)
}
function title(code) {
if (code === marker || code === null || markdownLineEnding(code)) {
effects.exit('chunkString')
return atTitleBreak(code)
}
effects.consume(code)
return code === 92 ? titleEscape : title
}
function titleEscape(code) {
if (code === marker || code === 92) {
effects.consume(code)
return title
}
return title(code)
}
}
module.exports = titleFactory