Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7590995e4 | |||
| d7b4b48cc7 |
@@ -3356,16 +3356,23 @@ async function showDetail(id, todoPage = 1, todoFilter = 'all') {
|
||||
|
||||
if (item.content) {
|
||||
html += `<div class="mb-3">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div class="d-flex justify-content-between align-items-center mb-1">
|
||||
<strong>内容:</strong>
|
||||
<small class="text-muted"><i class="bi bi-hand-index"></i> 可先选中部分文本,再双击在此处插入</small>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="markdownToggle-${item.id}-content"
|
||||
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 markdown-content quick-insert-area"
|
||||
<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')"
|
||||
style="cursor: pointer;">
|
||||
${renderMarkdown(item.content)}
|
||||
${localStorage.getItem('markdownDisplay') === 'false' ? `<pre style="white-space: pre-wrap; word-break: break-all;">${escapeHtml(item.content)}</pre>` : renderMarkdown(item.content)}
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
@@ -3482,16 +3489,23 @@ async function showDetail(id, todoPage = 1, todoFilter = 'all') {
|
||||
|
||||
if (item.note) {
|
||||
html += `<div class="mb-3">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div class="d-flex justify-content-between align-items-center mb-1">
|
||||
<strong>详情/备注:</strong>
|
||||
<small class="text-muted"><i class="bi bi-hand-index"></i> 可先选中部分文本,再双击在此处插入</small>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" id="markdownToggle-${item.id}-note"
|
||||
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 markdown-content quick-insert-area"
|
||||
<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')"
|
||||
style="cursor: pointer;">
|
||||
${renderMarkdown(item.note)}
|
||||
${localStorage.getItem('markdownDisplay') === 'false' ? `<pre style="white-space: pre-wrap; word-break: break-all;">${escapeHtml(item.note)}</pre>` : renderMarkdown(item.note)}
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
@@ -4028,6 +4042,51 @@ function escapeHtml(str) {
|
||||
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
}
|
||||
|
||||
// 转义HTML属性值(用于传递到 data 属性)
|
||||
function escapeHtmlAttr(str) {
|
||||
if (!str) return '';
|
||||
// 转义双引号和特殊字符,用于 HTML 属性值
|
||||
return str.replace(/&/g, '&')
|
||||
.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) {
|
||||
const displayEl = document.getElementById(`${field}Display-${itemId}`);
|
||||
if (!displayEl) return;
|
||||
|
||||
const rawContent = decodeHtmlAttr(displayEl.dataset.rawContent || '');
|
||||
const isMarkdown = localStorage.getItem('markdownDisplay') !== 'false';
|
||||
|
||||
// 切换状态
|
||||
localStorage.setItem('markdownDisplay', isMarkdown ? 'false' : 'true');
|
||||
|
||||
// 更新显示
|
||||
if (isMarkdown) {
|
||||
// 当前是Markdown,切换到原始文本
|
||||
displayEl.innerHTML = `<pre style="white-space: pre-wrap; word-break: break-all;">${escapeHtml(rawContent)}</pre>`;
|
||||
} else {
|
||||
// 当前是原始文本,切换到Markdown
|
||||
displayEl.innerHTML = renderMarkdown(rawContent);
|
||||
}
|
||||
|
||||
// 同步更新其他开关状态
|
||||
document.querySelectorAll(`input[id^="markdownToggle-${itemId}"]`).forEach(toggle => {
|
||||
toggle.checked = localStorage.getItem('markdownDisplay') !== 'false';
|
||||
});
|
||||
}
|
||||
|
||||
// 简单Markdown渲染(支持标题、粗体、斜体、代码、链接、列表)
|
||||
function renderMarkdown(text) {
|
||||
if (!text) return '';
|
||||
|
||||
Reference in New Issue
Block a user