UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

71 lines (70 loc) • 2.2 kB
import "./src-H3RMXyFL.mjs"; import { t as expectDefined } from "./expect-DDakjvvQ.mjs"; import { t as MarkdownItCallable } from "./markdown-it-CUTXHjwL.mjs"; //#region packages/markdown-core/src/image-spans.ts let imageParser; function createImageParser() { const e = new MarkdownItCallable("commonmark"); e.inline.ruler.enableOnly(["image"]); const t = expectDefined(e.inline.ruler.getRules("")[0], "Markdown image rule"); e.configure("commonmark"); e.core.ruler.disable("inline"); e.normalizeLink = (e) => e; e.validateLink = () => true; e.inline.ruler.at("image", (e, n) => { const r = e.pos; const i = t(e, n); if (i && !n) e.env.onImage(e, r); return i; }); return e; } /** Finds inline image destinations without treating code or escaped syntax as media. */ function findMarkdownImageSpans(e) { if (!e.includes("![")) return []; const t = imageParser ??= createImageParser(); const n = []; let r = ""; let i = []; let a = 0; const sourceOffset = (e) => { for (let t = i[a + 1]; t && t.start <= e; t = i[a + 1]) a += 1; return e + expectDefined(i[a], "Markdown inline line").offset; }; const o = { onImage: (e, t) => { if (e.src !== r) return; const i = expectDefined(e.tokens.at(-1), "Parsed Markdown image"); if (i.meta?.label) return; n.push({ start: sourceOffset(t), end: sourceOffset(e.pos), destination: String(expectDefined(i.attrGet("src"), "Markdown image destination")) }); } }; const s = t.parse(e, o); const c = [0]; for (const t of e.matchAll(/\r\n?|\n/g)) c.push(t.index + t[0].length); const l = e.replace(/\0/g, "�").split(/\r\n?|\n/); for (const e of s) { if (e.type !== "inline" || !e.map || !e.content.includes("![")) continue; r = e.content; const n = e.map[0]; let s = 0; i = r.split("\n").map((e, t) => { const r = expectDefined(l[n + t], "Markdown source line"); const i = e.trimStart(); const a = expectDefined(c[n + t], "Markdown source offset") + r.indexOf(i) - (e.length - i.length) - s; const o = { start: s, offset: a }; s += e.length + 1; return o; }); a = 0; t.inline.parse(r, t, o, []); } return n; } //#endregion export { findMarkdownImageSpans as t };