From b8ab51337769083f66b30abe9f170bb79b548f81 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Fri, 20 Nov 2026 00:34:45 +0800 Subject: [PATCH] =?UTF-8?q?125=E7=BB=AD15l-8:=20=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=A1=B5=E5=8D=8F=E8=AE=AE=E5=BC=B9=E7=AA=97=E5=81=9Amarkdown?= =?UTF-8?q?=E6=B8=B2=E6=9F=93,=20=E4=B8=8D=E5=86=8D=E5=B9=B2=E5=B7=B4?= =?UTF-8?q?=E5=B7=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前弹窗直接 textContent 端原文(裸###/裸-/裸**), 到php高度自由化了还做不出渲染 修复: - login.php 新增 renderMarkdownLite+inlineMd+esc(与player.php同范式), 标题/列表/加粗/斜体/代码/引用/链接 - 弹窗 body 改 innerHTML 渲染, 占位文本(加载中/失败/未配置)仍用 textContent 防注入 - .ag-body white-space pre-wrap→normal, 加 markdown 渲染样式(ag-h/ag-h2/ag-h3/ag-quote/code/li) 渲染验证: player.md 标题分级/列表/加粗/代码/引用块全部正常 --- login.php | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/login.php b/login.php index c637c26..3bc46ac 100644 --- a/login.php +++ b/login.php @@ -91,9 +91,18 @@ require_once __DIR__ . '/captcha_guard.php'; .ag-modal .ag-close { cursor: pointer; color: var(--dim); font-size: 20px; line-height: 1; } .ag-body { padding: 14px 18px; overflow-y: auto; flex: 1; - font-size: 13px; line-height: 1.75; color: var(--text); white-space: pre-wrap; + font-size: 13px; line-height: 1.75; color: var(--text); white-space: normal; word-break: break-word; } + /* 协议 markdown 渲染样式(标题/列表/加粗/引用/代码/段落) */ + .ag-body h1, .ag-body .ag-h { font-size: 18px; font-weight: 700; color: var(--accent); margin: 14px 0 8px; } + .ag-body .ag-h2 { font-size: 15px; font-weight: 700; color: var(--accent); margin: 12px 0 6px; } + .ag-body .ag-h3 { font-size: 14px; font-weight: 600; color: var(--text); margin: 10px 0 5px; } + .ag-body ul { margin: 6px 0 8px 4px; padding-left: 18px; } + .ag-body li { margin: 3px 0; } + .ag-body .ag-quote { border-left: 3px solid var(--yellow); padding: 6px 12px; margin: 8px 0; background: rgba(210,153,34,0.08); border-radius: 4px; } + .ag-body code { background: rgba(136,136,136,0.2); padding: 1px 5px; border-radius: 3px; font-size: 0.9em; } + .ag-body .ag-p { margin: 4px 0; } .ag-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; @@ -333,7 +342,7 @@ require_once __DIR__ . '/captcha_guard.php'; const res = await fetch(url, { method: 'POST', headers: {'Content-Type': 'application/json'} }); const data = await res.json(); if (data.success && data.data && data.data.has_agreement && (data.data.content || '').trim() !== '') { - body.textContent = data.data.content; + body.innerHTML = renderMarkdownLite(data.data.content); // ★ 渲染 markdown(标题/列表/加粗/引用) document.getElementById('agModalTitle').textContent = data.data.title || AG.title; AG_LOADED = true; // ★ 原文到位 AG_HAS_CONTENT = true; // ★ 有实际内容 @@ -402,6 +411,62 @@ require_once __DIR__ . '/captcha_guard.php'; } // 点「我已完成阅读」→ 关闭弹窗并自动勾选 + // ===== 轻量 markdown → HTML 渲染(登录弹窗用,无外部依赖,与 player.php 同范式)===== + function renderMarkdownLite(md) { + if (!md) return ''; + const lines = String(md).split(/\r?\n/); + let html = ''; + let inList = false; + const closeList = () => { if (inList) { html += ''; inList = false; } }; + for (let raw of lines) { + let s = raw; + // 表格分隔线丢弃 + if (s.trim().match(/^\|?[\s:|-]+\|?$/) && s.trim().length > 1 && s.includes('-')) { closeList(); continue; } + // 代码围栏 ``` 整行丢弃(后端已剥 json 块,双保险) + if (s.trim().startsWith('```')) { closeList(); continue; } + // 标题 #/##/### + const hm = s.match(/^(#{1,6})\s+(.*)$/); + if (hm) { + closeList(); + const lvl = hm[1].length; + const cls = lvl <= 2 ? (lvl === 1 ? 'ag-h' : 'ag-h2') : 'ag-h3'; + html += `
${inlineMd(hm[2])}
`; + continue; + } + // 无序列表 -/*/+ + if (s.match(/^\s*[-*+]\s+/)) { + if (!inList) { html += '