docutils-ts
Version:
Port of the Python Docutils library to TypeScript
66 lines (65 loc) • 2.36 kB
JavaScript
import { StateMachine } from './stateMachine.js';
class StateMachineWS extends StateMachine {
getIndented(labeled) {
const cArgs = { ...labeled };
if (typeof labeled.stripIndent === 'undefined') {
cArgs.stripIndent = true;
}
let offset = this.absLineOffset() || 0;
const [indented, indent, blankFinish] = this.inputLines.getIndented({
start: this.lineOffset,
untilBlank: cArgs.untilBlank,
stripIndent: cArgs.stripIndent,
});
if (indented) {
this.nextLine(indented.length - 1);
}
while (indented && indented.length && !(indented[0].trim())) {
indented.trimStart();
offset += 1;
}
return [indented, indent, offset, blankFinish];
}
getKnownIndented(labeled) {
const cArgs = { ...labeled };
if (typeof cArgs.stripIndent === 'undefined') {
cArgs.stripIndent = true;
}
let offset = this.absLineOffset() || 0;
const [indented, indent, blankFinish] = this.inputLines.getIndented({
start: this.lineOffset,
untilBlank: cArgs.untilBlank, stripIndent: cArgs.stripIndent, blockIndent: cArgs.indent,
});
this.nextLine(indented.length - 1);
while (indented.length && !(indented[0].trim())) {
indented.trimStart();
offset += 1;
}
return [indented, offset, blankFinish];
}
getFirstKnownIndented(args) {
const cArgs = { ...args };
if (cArgs.stripIndent === undefined) {
cArgs.stripIndent = true;
}
if (cArgs.stripTop === undefined) {
cArgs.stripTop = true;
}
let offset = this.absLineOffset() || 0;
const [indented, indent, blankFinish] = this.inputLines.getIndented({
start: this.lineOffset,
untilBlank: cArgs.untilBlank,
stripIndent: cArgs.stripIndent,
firstIndent: cArgs.indent,
});
this.nextLine(indented.length - 1);
if (cArgs.stripTop) {
while (indented.length && !(indented[0].trim())) {
indented.trimStart();
offset += 1;
}
}
return [indented, indent, offset, blankFinish];
}
}
export default StateMachineWS;