`, ``, ` `,
// ` `. The name must follow `<` IMMEDIATELY, which is what keeps
// prose like "ratio < 3:1" and "a < b > c" untouched, and the `>` must be present, which keeps
// "x]*)?\/?>/g;
/** One message, safe to drop into Markdown: every bare HTML tag becomes a code span.
*
* Idempotent by construction — a tag already inside backticks is skipped, because the text is
* split on code spans first and only the gaps are rewritten. That matters: several callers
* compose (a message joined into a table cell, then into a details block), and double-wrapping
* would produce ``` ```` ``` and render the backticks themselves. */
export function mdText(s: string): string {
let out = "";
let last = 0;
CODE_SPAN.lastIndex = 0;
for (let m = CODE_SPAN.exec(s); m; m = CODE_SPAN.exec(s)) {
out += escapeTags(s.slice(last, m.index)) + m[0];
last = m.index + m[0].length;
}
return out + escapeTags(s.slice(last));
}
function escapeTags(s: string): string {
return s.replace(TAG, (tag) => `\`${tag}\``);
}