refactor: simplify pass (trekexecute)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
76f74793e9
commit
52c382c198
8 changed files with 45 additions and 52 deletions
|
|
@ -86,12 +86,20 @@ function gitFailed(what, r) {
|
|||
|
||||
const short = (c) => c.slice(0, 12);
|
||||
|
||||
/** Where the managed block's start marker (`s`) and end marker (`e`) are; null when either is missing. */
|
||||
function blockBounds(text) {
|
||||
const s = text.indexOf(MARK_START);
|
||||
if (s === -1) return null;
|
||||
const e = text.indexOf(MARK_END, s + MARK_START.length);
|
||||
if (e === -1) return null;
|
||||
return { s, e };
|
||||
}
|
||||
|
||||
/** The lessons text with its managed block (start marker to end marker, plus its newline) taken out. */
|
||||
function outsideBlock(text) {
|
||||
const s = text.indexOf(MARK_START);
|
||||
if (s === -1) return text;
|
||||
const e = text.indexOf(MARK_END, s + MARK_START.length);
|
||||
if (e === -1) return text;
|
||||
const b = blockBounds(text);
|
||||
if (!b) return text;
|
||||
const { s, e } = b;
|
||||
let end = e + MARK_END.length;
|
||||
if (text.startsWith('\r\n', end)) end += 2;
|
||||
else if (text[end] === '\n') end += 1;
|
||||
|
|
@ -100,11 +108,9 @@ function outsideBlock(text) {
|
|||
|
||||
/** The non-blank lines inside the managed block (the same block `outsideBlock` takes out); none without one. */
|
||||
function blockLines(text) {
|
||||
const s = text.indexOf(MARK_START);
|
||||
if (s === -1) return [];
|
||||
const e = text.indexOf(MARK_END, s + MARK_START.length);
|
||||
if (e === -1) return [];
|
||||
return text.slice(s + MARK_START.length, e).split(/\r?\n/).filter((l) => l.trim() !== '');
|
||||
const b = blockBounds(text);
|
||||
if (!b) return [];
|
||||
return text.slice(b.s + MARK_START.length, b.e).split(/\r?\n/).filter((l) => l.trim() !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue