From a7590995e48281a9ff65df846bea7376509a5348 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Fri, 24 Apr 2026 13:04:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Markdown=E5=BC=80=E5=85=B3=E6=94=B9?= =?UTF-8?q?=E7=94=A8data=E5=B1=9E=E6=80=A7=E5=AD=98=E5=82=A8=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2=E5=A4=B1?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xian_favor/api.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/xian_favor/api.py b/xian_favor/api.py index fe6db4b..ef8e2c1 100644 --- a/xian_favor/api.py +++ b/xian_favor/api.py @@ -3360,13 +3360,14 @@ async function showDetail(id, todoPage = 1, todoFilter = 'all') { 内容:
+ onchange="toggleMarkdownDisplay(${item.id}, 'content')" + ${localStorage.getItem('markdownDisplay') !== 'false' ? 'checked' : ''}>
详情/备注:
+ onchange="toggleMarkdownDisplay(${item.id}, 'note')" + ${localStorage.getItem('markdownDisplay') !== 'false' ? 'checked' : ''}>
/g, '>'); } -// 转义HTML属性值(用于传递到 onclick 等属性) +// 转义HTML属性值(用于传递到 data 属性) function escapeHtmlAttr(str) { if (!str) return ''; - // 先转义HTML,然后转义单引号和反斜杠 - return escapeHtml(str).replace(/'/g, '\\'').replace(/"/g, '"').replace(/\\n/g, '\\n'); + // 转义双引号和特殊字符,用于 HTML 属性值 + return str.replace(/&/g, '&') + .replace(/"/g, '"') + .replace(//g, '>'); +} + +// 从 data 属性解码内容 +function decodeHtmlAttr(str) { + if (!str) return ''; + return str.replace(/"/g, '"') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&/g, '&'); } // 切换Markdown显示模式 -function toggleMarkdownDisplay(itemId, field, rawContent) { +function toggleMarkdownDisplay(itemId, field) { const displayEl = document.getElementById(`${field}Display-${itemId}`); + if (!displayEl) return; + + const rawContent = decodeHtmlAttr(displayEl.dataset.rawContent || ''); const isMarkdown = localStorage.getItem('markdownDisplay') !== 'false'; // 切换状态 @@ -4058,10 +4075,10 @@ function toggleMarkdownDisplay(itemId, field, rawContent) { // 更新显示 if (isMarkdown) { // 当前是Markdown,切换到原始文本 - displayEl.innerHTML = `
${escapeHtml(rawContent.replace(/\\n/g, '\\n').replace(/'/g, "'"))}
`; + displayEl.innerHTML = `
${escapeHtml(rawContent)}
`; } else { // 当前是原始文本,切换到Markdown - displayEl.innerHTML = renderMarkdown(rawContent.replace(/\\n/g, '\\n').replace(/'/g, "'")); + displayEl.innerHTML = renderMarkdown(rawContent); } // 同步更新其他开关状态