mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 01:31:10 +00:00
* 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>
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { markdownToIR, sliceMarkdownIR } from "./ir.js";
|
|
import { renderMarkdownWithMarkers } from "./render.js";
|
|
|
|
describe("renderMarkdownWithMarkers semantic annotations", () => {
|
|
it("renders transcript annotations while suppressing nested marker syntax", () => {
|
|
const ir = markdownToIR("**user[Thu 2026-07-02] continue**", {
|
|
assistantTranscriptRoleHeaders: true,
|
|
});
|
|
|
|
expect(
|
|
renderMarkdownWithMarkers(ir, {
|
|
annotationMarkers: {
|
|
assistant_transcript_role: {
|
|
open: "`",
|
|
close: "`",
|
|
suppressNestedFormatting: true,
|
|
},
|
|
},
|
|
styleMarkers: { bold: { open: "*", close: "*" } },
|
|
escapeText: (text) => text,
|
|
}),
|
|
).toBe("`user[Thu 2026-07-02]`* continue*");
|
|
});
|
|
|
|
it("keeps annotations when an IR slice starts inside the marked header", () => {
|
|
const ir = markdownToIR("user[Thu 2026-07-02] continue", {
|
|
assistantTranscriptRoleHeaders: true,
|
|
});
|
|
const sliced = sliceMarkdownIR(ir, 4, ir.text.length);
|
|
|
|
expect(sliced.annotations).toEqual([
|
|
expect.objectContaining({ start: 0, end: "[Thu 2026-07-02]".length }),
|
|
]);
|
|
});
|
|
|
|
it("closes and reopens formatting that crosses an annotation boundary", () => {
|
|
const ir = markdownToIR("user[**Thu] trailing**", {
|
|
assistantTranscriptRoleHeaders: true,
|
|
});
|
|
|
|
expect(
|
|
renderMarkdownWithMarkers(ir, {
|
|
annotationMarkers: {
|
|
assistant_transcript_role: { open: "`", close: "`" },
|
|
},
|
|
styleMarkers: { bold: { open: "*", close: "*" } },
|
|
escapeText: (text) => text,
|
|
}),
|
|
).toBe("`user[*Thu]*`* trailing*");
|
|
});
|
|
|
|
it("keeps structural containers outside dominant annotations", () => {
|
|
const ir = markdownToIR("> user[Thu 2026-07-02] continue", {
|
|
assistantTranscriptRoleHeaders: true,
|
|
});
|
|
|
|
expect(
|
|
renderMarkdownWithMarkers(ir, {
|
|
annotationMarkers: {
|
|
assistant_transcript_role: {
|
|
open: "<code>",
|
|
close: "</code>",
|
|
suppressNestedFormatting: true,
|
|
},
|
|
},
|
|
styleMarkers: { blockquote: { open: "<blockquote>", close: "</blockquote>" } },
|
|
escapeText: (text) => text,
|
|
}),
|
|
).toBe("<blockquote><code>user[Thu 2026-07-02]</code> continue</blockquote>");
|
|
});
|
|
|
|
it("renders many independently styled annotations without cross-product scans", () => {
|
|
const markdown = Array.from(
|
|
{ length: 256 },
|
|
(_, index) => `**user[t${index}]** line ${index}`,
|
|
).join("\n");
|
|
const ir = markdownToIR(markdown, { assistantTranscriptRoleHeaders: true });
|
|
const rendered = renderMarkdownWithMarkers(ir, {
|
|
annotationMarkers: {
|
|
assistant_transcript_role: {
|
|
open: "`",
|
|
close: "`",
|
|
suppressNestedFormatting: true,
|
|
},
|
|
},
|
|
styleMarkers: { bold: { open: "*", close: "*" } },
|
|
escapeText: (text) => text,
|
|
});
|
|
|
|
expect(rendered.match(/`user\[t\d+\]`/gu)).toHaveLength(256);
|
|
});
|
|
});
|