fix: 修复JS正则表达式在模板字符串中被破坏的问题

This commit is contained in:
2026-04-22 12:22:07 +08:00
parent eec8b477be
commit 407a63f3cf

View File

@@ -3050,7 +3050,7 @@ function renderMarkdown(text) {
let html = escapeHtml(text);
// 代码块 ```code```
html = html.replace(/```(\w*)\n([\s\S]*?)```/g, '<pre class="bg-dark text-light p-2 rounded"><code>$2</code></pre>');
html = html.replace(/```(\\w*)\\n([\\s\\S]*?)```/g, '<pre class="bg-dark text-light p-2 rounded"><code>$2</code></pre>');
// 行内代码 `code`
html = html.replace(/`([^`]+)`/g, '<code class="bg-light px-1 rounded">$1</code>');
@@ -3072,16 +3072,16 @@ function renderMarkdown(text) {
// 无序列表 - item
html = html.replace(/^- (.+)$/gm, '<li class="ms-3">$1</li>');
html = html.replace(/(<li.*<\/li>\n?)+/g, '<ul class="mb-2">$&</ul>');
html = html.replace(/(<li.*<\\/li>\\n?)+/g, '<ul class="mb-2">$&</ul>');
// 有序列表 1. item
html = html.replace(/^\d+\. (.+)$/gm, '<li class="ms-3">$1</li>');
html = html.replace(/^\\d+\\. (.+)$/gm, '<li class="ms-3">$1</li>');
// 段落分隔(两个换行)
html = html.replace(/\n\n/g, '</p><p class="mb-2">');
html = html.replace(/\\n\\n/g, '</p><p class="mb-2">');
// 单换行
html = html.replace(/\n/g, '<br>');
html = html.replace(/\\n/g, '<br>');
// 包装在段落中
if (!html.startsWith('<')) {