in src/commonMain/kotlin/org/intellij/markdown/parser/markerblocks/impl/CodeBlockMarkerBlock.kt [41:75]
override fun doProcessToken(pos: LookaheadText.Position, currentConstraints: MarkdownConstraints): MarkerBlock.ProcessingResult {
if (pos.offset < realInterestingOffset) {
return MarkerBlock.ProcessingResult.CANCEL
}
// Eat everything if we're on code line
if (pos.offsetInCurrentLine != -1) {
return MarkerBlock.ProcessingResult.CANCEL
}
assert(pos.offsetInCurrentLine == -1)
val nonemptyPos = MarkdownParserUtil.findNonEmptyLineWithSameConstraints(constraints, pos)
?: return MarkerBlock.ProcessingResult.DEFAULT
val nextConstraints = constraints.applyToNextLineAndAddModifiers(nonemptyPos)
val shifted = nonemptyPos.nextPosition(1 + nextConstraints.getCharsEaten(nonemptyPos.currentLine))
val nonWhitespace = shifted?.nextPosition(shifted.charsToNonWhitespace() ?: 0)
?: return MarkerBlock.ProcessingResult.DEFAULT
if (!MarkdownParserUtil.hasCodeBlockIndent(nonWhitespace, nextConstraints)) {
return MarkerBlock.ProcessingResult.DEFAULT
} else {
// We'll add the current line anyway
val nextLineConstraints = constraints.applyToNextLineAndAddModifiers(pos)
val nodeRange = pos.offset + 1 + nextLineConstraints.getCharsEaten(pos.currentLine)..pos.nextLineOrEofOffset
if (nodeRange.last - nodeRange.first > 0) {
productionHolder.addProduction(listOf(SequentialParser.Node(
nodeRange, MarkdownTokenTypes.CODE_LINE)))
}
realInterestingOffset = pos.nextLineOrEofOffset
return MarkerBlock.ProcessingResult.CANCEL
}
}