From 9f483c0643e7c5e3e8d14af83f61d239debbdf66 Mon Sep 17 00:00:00 2001
From: HuangHai <10402852@qq.com>
Date: Wed, 21 Jan 2026 10:10:30 +0800
Subject: [PATCH] 'commit'
---
static/douyin.html | 48 ++++++++-----
static/js/douyin.js | 172 ++++++++++++++++++++++----------------------
2 files changed, 117 insertions(+), 103 deletions(-)
diff --git a/static/douyin.html b/static/douyin.html
index f57b4f7..563fc07 100644
--- a/static/douyin.html
+++ b/static/douyin.html
@@ -164,39 +164,53 @@
-
-
-
-
+
+
+
+
+
diff --git a/static/js/douyin.js b/static/js/douyin.js
index 6a10efc..1fa13e7 100644
--- a/static/js/douyin.js
+++ b/static/js/douyin.js
@@ -1,5 +1,75 @@
const { createApp, ref, computed, onMounted } = Vue;
+// 1. 全局渲染器 - 纯手写的高鲁棒性解析器,不再依赖 marked
+const globalRenderMarkdown = (text) => {
+ if (!text) return '';
+
+ // 0. 预处理:去除 AI 可能返回的代码块标记
+ let cleanText = text.trim();
+ // 去除开头的 ```markdown 或 ```
+ cleanText = cleanText.replace(/^```(markdown)?\s*/i, '');
+ // 去除结尾的 ```
+ cleanText = cleanText.replace(/```\s*$/, '');
+
+ // 1. 预处理:按行分割
+ const lines = cleanText.split('\n');
+ let html = '';
+ let inList = false;
+
+ for (let i = 0; i < lines.length; i++) {
+ let line = lines[i];
+ // 关键:去除行首尾空白,解决缩进导致的解析失败
+ let trimmed = line.trim();
+
+ // 空行处理
+ if (!trimmed) {
+ if (inList) { html += '\n'; inList = false; }
+ continue; // 忽略空行,或者可以加
+ }
+
+ // 2. 内联格式处理(加粗、代码、链接)
+ // 加粗 **text** -> text
+ trimmed = trimmed.replace(/\*\*(.*?)\*\*/g, '$1');
+ // 代码 `text` -> text
+ trimmed = trimmed.replace(/`([^`]+)`/g, '$1');
+
+ // 3. 块级元素处理
+ // 标题 ### Title
+ if (trimmed.startsWith('###')) {
+ if (inList) { html += '\n'; inList = false; }
+ html += `
${trimmed}
`; + } + } + + if (inList) { html += '$1');
- };
- for (let line of lines) {
- let trimmed = line.trim();
- if (!trimmed) {
- if (inList) { html += ''; inList = false; }
- html += '${parseInline(trimmed)}
`; - } - } - if (inList) html += ''; - return html; - }; - - // Configure Marked - if (typeof marked !== 'undefined') { - marked.use({ - gfm: true, - breaks: true - }); - } - - // 增强的 Markdown & LaTeX 解析器 - const renderMarkdownAndLatex = (text) => { - if (!text) return ''; - - try { - let processedText = text; - - // 1. 处理 LaTeX - if (typeof katex !== 'undefined') { - // 处理块级 LaTeX: $$ ... $$ - processedText = processedText.replace(/\$\$\s*([\s\S]*?)\s*\$\$/g, (match, formula) => { - try { - return '