|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import {factorySpace} from 'micromark-factory-space' |
|
import {markdownLineEnding, markdownSpace} from 'micromark-util-character' |
|
import {codes} from 'micromark-util-symbol/codes.js' |
|
import {constants} from 'micromark-util-symbol/constants.js' |
|
import {types} from 'micromark-util-symbol/types.js' |
|
import {ok as assert} from 'uvu/assert' |
|
|
|
|
|
export const codeIndented = { |
|
name: 'codeIndented', |
|
tokenize: tokenizeCodeIndented |
|
} |
|
|
|
|
|
const furtherStart = {tokenize: tokenizeFurtherStart, partial: true} |
|
|
|
|
|
|
|
|
|
|
|
function tokenizeCodeIndented(effects, ok, nok) { |
|
const self = this |
|
return start |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function start(code) { |
|
|
|
assert(markdownSpace(code)) |
|
effects.enter(types.codeIndented) |
|
|
|
|
|
return factorySpace( |
|
effects, |
|
afterPrefix, |
|
types.linePrefix, |
|
constants.tabSize + 1 |
|
)(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function afterPrefix(code) { |
|
const tail = self.events[self.events.length - 1] |
|
return tail && |
|
tail[1].type === types.linePrefix && |
|
tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize |
|
? atBreak(code) |
|
: nok(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function atBreak(code) { |
|
if (code === codes.eof) { |
|
return after(code) |
|
} |
|
|
|
if (markdownLineEnding(code)) { |
|
return effects.attempt(furtherStart, atBreak, after)(code) |
|
} |
|
|
|
effects.enter(types.codeFlowValue) |
|
return inside(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function inside(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.codeFlowValue) |
|
return atBreak(code) |
|
} |
|
|
|
effects.consume(code) |
|
return inside |
|
} |
|
|
|
|
|
function after(code) { |
|
effects.exit(types.codeIndented) |
|
|
|
|
|
|
|
return ok(code) |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function tokenizeFurtherStart(effects, ok, nok) { |
|
const self = this |
|
|
|
return furtherStart |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function furtherStart(code) { |
|
|
|
|
|
if (self.parser.lazy[self.now().line]) { |
|
return nok(code) |
|
} |
|
|
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding) |
|
effects.consume(code) |
|
effects.exit(types.lineEnding) |
|
return furtherStart |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return factorySpace( |
|
effects, |
|
afterPrefix, |
|
types.linePrefix, |
|
constants.tabSize + 1 |
|
)(code) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function afterPrefix(code) { |
|
const tail = self.events[self.events.length - 1] |
|
return tail && |
|
tail[1].type === types.linePrefix && |
|
tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize |
|
? ok(code) |
|
: markdownLineEnding(code) |
|
? furtherStart(code) |
|
: nok(code) |
|
} |
|
} |
|
|