fix yt links

This commit is contained in:
2026-05-24 23:16:01 +02:00
parent 95e37c1dd1
commit fa8ed5e354

View File

@@ -1721,10 +1721,27 @@ class CommentSystem {
return `[audio](${fullUrl})`; return `[audio](${fullUrl})`;
}); });
// 3. Render Markdown for the line // 3. Render Markdown for the line.
let mdSafe = processedLine.replace(/\*/g, '\\*').replace(/_/g, '\\_'); // Protect URLs and already-formed Markdown link/image tokens from the
const bs = String.fromCharCode(92); // italic-prevention escaping pass so that underscores in query params
mdSafe = mdSafe.split(bs + bs + '_').join(bs + bs + bs + '_'); // (e.g. ?v=_FcvmypiHg4) are never turned into ?v=\_FcvmypiHg4.
const mdProtected = [];
// Match [text](url) / ![alt](url) tokens AND bare http(s) URLs
let mdSafe = processedLine.replace(
/(!?\[[^\]]*\]\([^)]*\))|https?:\/\/\S+/g,
(match) => {
const idx = mdProtected.length;
mdProtected.push(match);
return `\x02MDURL${idx}\x03`;
}
);
// Escape * and _ only in the non-URL portions
mdSafe = mdSafe
.replace(/\\/g, '\\\\')
.replace(/\*/g, '\\*')
.replace(/_/g, '\\_');
// Restore protected URLs/tokens
mdSafe = mdSafe.replace(/\x02MDURL(\d+)\x03/g, (_, i) => mdProtected[+i]);
let rendered = marked.parseInline let rendered = marked.parseInline
? marked.parseInline(mdSafe, { renderer: renderer }) ? marked.parseInline(mdSafe, { renderer: renderer })