fix(cli): preserve literal Markdown table facts (#7073)

* fix(cli): preserve literal Markdown table facts

* test(cli): retain capacity diagnostics through Markdown escaping

* fix(cli): keep intraword underscores readable in Markdown tables

Underscore runs between letters or digits cannot open or close CommonMark emphasis, so escaping them only adds noise to identifiers such as source_index and invalid_request in raw Markdown. Escape underscore runs only at word boundaries and restore the original diagnostic assertions.
This commit is contained in:
RRFZ authored and GitHub committed 2026-10-25 13:55:18 +08:00
1 parent fead4fdaa7
commit cc146042d1
5 files changed
+137 -15

No files matched your search

+16 -2
View File
@@ -43,13 +43,27 @@ const isObjectArray = (value: unknown): value is Record<string, unknown>[] =>
) &&
value.some((item) => Object.keys(item).length > 0);
const isWordCharacter = (character: string | undefined): boolean =>
character !== undefined && /[\p{L}\p{N}]/u.test(character);
/** Underscore runs between word characters cannot open or close emphasis. */
const escapeInlineSyntax = (
match: string,
offset: number,
text: string,
): string =>
match.startsWith("_") &&
isWordCharacter(text[offset - 1]) &&
isWordCharacter(text[offset + match.length])
? match
: match.replace(/./g, "\\$&");
const escapeTableCell = (value: string): string =>
value
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\\/g, "\\\\")
.replace(/\|/g, "\\|")
.replace(/[\\|`*[\]~]|_+/g, escapeInlineSyntax)
.replace(/\r\n|\r|\n/g, "<br>");
const renderTable = (