import test from "node:test";
import assert from "node:assert/strict";
import {
escapeUnknownHtmlTagsForDisplay,
hasVisibleMarkdownContent,
normalizeMarkdownForDisplay,
} from "../lib/markdown-display";
test("normalizeMarkdownForDisplay removes empty details blocks", () => {
const input = "Before\n\n
\n\nAfter";
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
});
test("normalizeMarkdownForDisplay removes raw html control placeholders", () => {
const input =
'Before\n\n\n\n\n\nAfter';
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
});
test("normalizeMarkdownForDisplay removes empty markdown tables", () => {
const input = "Before\n\n| |\n|---|\n\nAfter";
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
});
test("normalizeMarkdownForDisplay removes empty html tables", () => {
const input = "Before\n\n
\n\nAfter";
assert.equal(normalizeMarkdownForDisplay(input), "Before\n\nAfter");
});
test("normalizeMarkdownForDisplay keeps meaningful tables", () => {
const input = "Before\n\n| Topic |\n|---|\n| Math |\n\nAfter";
assert.equal(normalizeMarkdownForDisplay(input), input);
});
test("escapeUnknownHtmlTagsForDisplay escapes LLM pseudo tags", () => {
const input = "Before\ninternal scratchpad\nAfter";
assert.equal(
escapeUnknownHtmlTagsForDisplay(input),
"Before\n``internal scratchpad``\nAfter",
);
});
test("escapeUnknownHtmlTagsForDisplay preserves line count for previews", () => {
const input = "A\n\nhidden\nB";
const output = escapeUnknownHtmlTagsForDisplay(input);
assert.equal(output.split("\n").length, input.split("\n").length);
});
test("escapeUnknownHtmlTagsForDisplay keeps allowed html tags", () => {
const input = "More
Body ";
assert.equal(escapeUnknownHtmlTagsForDisplay(input), input);
});
test("hasVisibleMarkdownContent rejects empty raw-html placeholders", () => {
assert.equal(
hasVisibleMarkdownContent("
"),
false,
);
});
test("hasVisibleMarkdownContent rejects raw html control placeholders", () => {
assert.equal(
hasVisibleMarkdownContent('\n'),
false,
);
});
test("hasVisibleMarkdownContent rejects empty markdown tables", () => {
assert.equal(hasVisibleMarkdownContent("| |\n|---|"), false);
});
test("hasVisibleMarkdownContent keeps meaningful markdown", () => {
assert.equal(
hasVisibleMarkdownContent("这是一个正常回复。\n\n- 第一条"),
true,
);
});