openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
20 lines (19 loc) • 965 B
JavaScript
import { n as findMarkdownCodeRegions } from "./reasoning-tags-DQnFHfqj.js";
//#region src/shared/text/code-regions.ts
/** Finds CommonMark block-aware fenced, indented, and inline code regions. */
function findCodeRegions(text, options) {
return findMarkdownCodeRegions(text, options);
}
/** Returns true when a character offset falls inside one of the discovered code regions. */
function isInsideCode(pos, regions) {
return regions.some((region) => pos >= region.start && pos < region.end);
}
/** Removes control lines while retaining literal code and original line endings. */
function stripLinesOutsideCode(text, shouldStrip) {
let regions;
return text.replace(/[^\n]*(?:\n|$)/g, (raw, offset) => {
return shouldStrip(raw.endsWith("\n") ? raw.slice(0, -1).replace(/\r$/, "") : raw) && !isInsideCode(offset, regions ??= findCodeRegions(text)) ? "" : raw;
});
}
//#endregion
export { isInsideCode as n, stripLinesOutsideCode as r, findCodeRegions as t };