web: open authored stage definitions in managed graph popup
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// Exact source ranges, following internal/pipeline/definition.go's block rules.
|
||||
// Never reserialize graph fields: defaults and authored spelling differ.
|
||||
export function stageSource(source, key) {
|
||||
if (typeof source !== "string") return null;
|
||||
let active = false;
|
||||
let start = null;
|
||||
let offset = 0;
|
||||
for (const line of source.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
|
||||
const trim = line.trim();
|
||||
if (active) {
|
||||
if (trim === "```") active = false;
|
||||
} else if (trim.startsWith("# stage ")) {
|
||||
if (start !== null) return source.slice(start, offset);
|
||||
if (trim.slice(8).trim() === key) start = offset;
|
||||
} else if (trim.startsWith("```")) {
|
||||
active = true;
|
||||
}
|
||||
offset += line.length;
|
||||
}
|
||||
return start === null ? null : source.slice(start);
|
||||
}
|
||||
Reference in New Issue
Block a user