UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

32 lines (31 loc) • 929 B
//#region src/shared/markdown-code.ts function longestBacktickRun(e) { let t = 0; let n = 0; for (const r of e) { if (r === "`") { n += 1; t = Math.max(t, n); continue; } n = 0; } return t; } /** * Wraps text in an inline code span whose delimiter is longer than any * backtick run inside it. Edge backticks and newlines get spacer padding so * renderers do not glue the delimiter onto the content. */ function formatInlineCodeSpan(e) { const t = "`".repeat(longestBacktickRun(e) + 1); const n = e.startsWith("`") || e.endsWith("`") || e.includes("\n") ? " " : ""; return `${t}${n}${e}${n}${t}`; } /** Wraps text in a fenced code block whose fence is longer than any run inside it. */ function formatFencedCodeBlock(e, t) { const n = "`".repeat(Math.max(3, longestBacktickRun(e) + 1)); return `${n}${t ?? ""}\n${e}\n${n}`; } //#endregion export { formatInlineCodeSpan as n, formatFencedCodeBlock as t };