mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-09 17:22:53 +00:00
Comment-only follow-up documenting reusable gateway, auth, proxy, device, Talk, session, and agent helper contracts.\n\nVerification: git diff --check plus targeted tests recorded in PR body.
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { markdownToIRWithMeta } from "./ir.js";
|
|
import { renderMarkdownWithMarkers } from "./render.js";
|
|
import type { MarkdownTableMode } from "./types.js";
|
|
|
|
const MARKDOWN_STYLE_MARKERS = {
|
|
bold: { open: "**", close: "**" },
|
|
italic: { open: "_", close: "_" },
|
|
strikethrough: { open: "~~", close: "~~" },
|
|
code: { open: "`", close: "`" },
|
|
code_block: { open: "```\n", close: "```" },
|
|
} as const;
|
|
|
|
/** Converts markdown tables into the configured plaintext/code rendering mode. */
|
|
export function convertMarkdownTables(markdown: string, mode: MarkdownTableMode): string {
|
|
if (!markdown || mode === "off") {
|
|
return markdown;
|
|
}
|
|
const effectiveMode = mode === "block" ? "code" : mode;
|
|
const { ir, hasTables } = markdownToIRWithMeta(markdown, {
|
|
linkify: false,
|
|
autolink: false,
|
|
headingStyle: "none",
|
|
blockquotePrefix: "",
|
|
tableMode: effectiveMode,
|
|
});
|
|
if (!hasTables) {
|
|
return markdown;
|
|
}
|
|
return renderMarkdownWithMarkers(ir, {
|
|
styleMarkers: MARKDOWN_STYLE_MARKERS,
|
|
escapeText: (text) => text,
|
|
buildLink: (link, text) => {
|
|
const href = link.href.trim();
|
|
if (!href) {
|
|
return null;
|
|
}
|
|
const label = text.slice(link.start, link.end);
|
|
if (!label) {
|
|
return null;
|
|
}
|
|
return { start: link.start, end: link.end, open: "[", close: `](${href})` };
|
|
},
|
|
});
|
|
}
|