micromark
Version:
small commonmark compliant markdown parser with positional info and concrete tokens
52 lines (41 loc) • 1.09 kB
JavaScript
import markdownLineEnding from '../character/markdown-line-ending.mjs'
import markdownSpace from '../character/markdown-space.mjs'
import spaceFactory from './factory-space.mjs'
var thematicBreak = {
name: 'thematicBreak',
tokenize: tokenizeThematicBreak
}
function tokenizeThematicBreak(effects, ok, nok) {
var size = 0
var marker
return start
function start(code) {
effects.enter('thematicBreak')
marker = code
return atBreak(code)
}
function atBreak(code) {
if (code === marker) {
effects.enter('thematicBreakSequence')
return sequence(code)
}
if (markdownSpace(code)) {
return spaceFactory(effects, atBreak, 'whitespace')(code)
}
if (size < 3 || (code !== null && !markdownLineEnding(code))) {
return nok(code)
}
effects.exit('thematicBreak')
return ok(code)
}
function sequence(code) {
if (code === marker) {
effects.consume(code)
size++
return sequence
}
effects.exit('thematicBreakSequence')
return atBreak(code)
}
}
export default thematicBreak