refactor: 第三方库替换 & 代码精简 — v5.1.5

- Markdown 解析器:内联正则 → marked 库(完整 GFM 支持)
- HTML 净化器:内联 DOM 遍历 → DOMPurify(业界标准)
- crypto.ts:删除 sha256js/xorBytes 死代码回退路径
- 消除 5 个文件中 escapeHtml/formatSize 重复定义
- 版本号升级至 5.1.5
This commit is contained in:
thzxx
2026-04-19 20:48:56 +08:00
parent 586cd33563
commit 8805858b79
15 changed files with 183 additions and 310 deletions
+2 -2
View File
@@ -44,9 +44,9 @@ export function formatSize(bytes: number): string {
/** HTML 转义 */
export function escapeHtml(str: string): string {
const map: Record<string, string> = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
return String(str).replace(/[&<>"']/g, (c) => map[c]);
return str.replace(/[&<>"']/g, (c) => ESCAPE_MAP[c]);
}
const ESCAPE_MAP: Record<string, string> = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
/** 根据文件名检测语言标识(用于 Markdown 代码块) */
export function detectLanguage(filename: string): string {