Compare commits

...

1 Commits

View File

@@ -3360,13 +3360,14 @@ async function showDetail(id, todoPage = 1, todoFilter = 'all') {
<strong>内容:</strong>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="markdownToggle-${item.id}-content"
onchange="toggleMarkdownDisplay(${item.id}, 'content', '${escapeHtmlAttr(item.content)}')"
${localStorage.getItem('markdownDisplay') === 'true' ? 'checked' : ''}>
onchange="toggleMarkdownDisplay(${item.id}, 'content')"
${localStorage.getItem('markdownDisplay') !== 'false' ? 'checked' : ''}>
<label class="form-check-label small" for="markdownToggle-${item.id}-content">Markdown</label>
</div>
</div>
<div class="border rounded p-3 bg-light quick-insert-area"
id="contentDisplay-${item.id}"
data-raw-content="${escapeHtmlAttr(item.content)}"
data-field="content"
data-item-id="${item.id}"
ondblclick="showQuickInsert(${item.id}, 'content')"
@@ -3492,13 +3493,14 @@ async function showDetail(id, todoPage = 1, todoFilter = 'all') {
<strong>详情/备注:</strong>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="markdownToggle-${item.id}-note"
onchange="toggleMarkdownDisplay(${item.id}, 'note', '${escapeHtmlAttr(item.note)}')"
${localStorage.getItem('markdownDisplay') === 'true' ? 'checked' : ''}>
onchange="toggleMarkdownDisplay(${item.id}, 'note')"
${localStorage.getItem('markdownDisplay') !== 'false' ? 'checked' : ''}>
<label class="form-check-label small" for="markdownToggle-${item.id}-note">Markdown</label>
</div>
</div>
<div class="border rounded p-3 bg-light quick-insert-area"
id="noteDisplay-${item.id}"
data-raw-content="${escapeHtmlAttr(item.note)}"
data-field="note"
data-item-id="${item.id}"
ondblclick="showQuickInsert(${item.id}, 'note')"
@@ -4040,16 +4042,31 @@ function escapeHtml(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// 转义HTML属性值用于传递到 onclick 等属性)
// 转义HTML属性值用于传递到 data 属性)
function escapeHtmlAttr(str) {
if (!str) return '';
// 转义HTML然后转义单引号和反斜杠
return escapeHtml(str).replace(/'/g, '\\&#39;').replace(/"/g, '&quot;').replace(/\\n/g, '\\n');
// 转义双引号和特殊字符,用于 HTML 属性值
return str.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
// 从 data 属性解码内容
function decodeHtmlAttr(str) {
if (!str) return '';
return str.replace(/&quot;/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/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 = `<pre style="white-space: pre-wrap; word-break: break-all;">${escapeHtml(rawContent.replace(/\\n/g, '\\n').replace(/'/g, "'"))}</pre>`;
displayEl.innerHTML = `<pre style="white-space: pre-wrap; word-break: break-all;">${escapeHtml(rawContent)}</pre>`;
} else {
// 当前是原始文本切换到Markdown
displayEl.innerHTML = renderMarkdown(rawContent.replace(/\\n/g, '\\n').replace(/'/g, "'"));
displayEl.innerHTML = renderMarkdown(rawContent);
}
// 同步更新其他开关状态