Files
openclaw/extensions/telegram/src/format-render.ts
snowzlmbot e8ad0466ff fix: render assistant transcript headers safely (#99404)
* fix: render assistant transcript headers safely

Co-authored-by: snowzlmbot <293528334+snowzlmbot@users.noreply.github.com>

* fix(markdown): nest crossing annotation spans

* fix(markdown): protect final transport projections

* refactor(markdown): split transcript render ownership

* test(ui): cover assistant transcript render flag

* refactor(markdown): keep transcript helpers private

* docs(changelog): note assistant transcript headers

* chore(plugin-sdk): refresh transcript annotation baseline

* fix(markdown): harden final transcript projections

* docs(changelog): defer transcript note to release

* refactor(markdown): centralize HTML tokenization

* fix(markdown): satisfy lint gates

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: snowzlmbot <293528334+snowzlmbot@users.noreply.github.com>
2026-07-14 02:25:37 -07:00

49 lines
1.5 KiB
TypeScript

import {
type MarkdownIR,
type MarkdownLinkSpan,
renderMarkdownWithMarkers,
} from "openclaw/plugin-sdk/text-chunking";
type TelegramRenderLink = {
start: number;
end: number;
open: string;
close: string;
};
export function renderTelegramMarkdownIR(
ir: MarkdownIR,
options: {
escapeText: (text: string) => string;
buildLink: (link: MarkdownLinkSpan, text: string) => TelegramRenderLink | null;
buildCodeBlockOpen: (span: { language?: string }) => string;
},
): string {
return renderMarkdownWithMarkers(ir, {
annotationMarkers: {
assistant_transcript_role: {
open: "<code>",
close: "</code>",
suppressNestedFormatting: true,
},
},
styleMarkers: {
bold: { open: "<b>", close: "</b>" },
italic: { open: "<i>", close: "</i>" },
strikethrough: { open: "<s>", close: "</s>" },
code: { open: "<code>", close: "</code>" },
code_block: { open: options.buildCodeBlockOpen, close: "</code></pre>" },
spoiler: { open: "<tg-spoiler>", close: "</tg-spoiler>" },
blockquote: { open: "<blockquote>", close: "</blockquote>" },
heading_1: { open: "<h1>", close: "</h1>" },
heading_2: { open: "<h2>", close: "</h2>" },
heading_3: { open: "<h3>", close: "</h3>" },
heading_4: { open: "<h4>", close: "</h4>" },
heading_5: { open: "<h5>", close: "</h5>" },
heading_6: { open: "<h6>", close: "</h6>" },
},
escapeText: options.escapeText,
buildLink: options.buildLink,
});
}