From a44abea40100063341c993a3f4cc4780b9d633db Mon Sep 17 00:00:00 2001 From: thzxx <1440196015@qq.com> Date: Fri, 24 Jul 2026 11:26:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20stability=20improvements=20=E2=80=94=20i?= =?UTF-8?q?nitialize=20=5FoutlineTimer,=20extract=20INLINE=5FRE=20constant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core.js: initialize this._outlineTimer = null in constructor (fixes clearTimeout(undefined)) - parser.js: extract INLINE_RE to module-level constant (avoid recompilation on every scanInline call) --- src/core.js | 1 + src/parser.js | 54 ++++++++++++++++++++------------------------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/core.js b/src/core.js index b79423e..b96ddbb 100644 --- a/src/core.js +++ b/src/core.js @@ -109,6 +109,7 @@ class MarkdownEditor { this._shortcuts = []; // v0.1.6: 快捷键注册表 this._contextMenuItems = []; // v0.1.6: 右键菜单项 this._customActions = {}; // 自定义工具栏动作 + this._outlineTimer = null; // 大纲防抖计时器 // 渲染函数:自定义覆盖内置解析器 this._renderFn = (typeof this.config.render === 'function') ? this.config.render : parseMarkdown; diff --git a/src/parser.js b/src/parser.js index 2daaea8..d0497bb 100644 --- a/src/parser.js +++ b/src/parser.js @@ -775,43 +775,31 @@ const extractInlineCodes = (text, codes) => { return result; }; +/** + * 单遍内联扫描正则(模块级常量,避免每次调用重新编译) + */ +const INLINE_RE = new RegExp([ + '(!\\[[^\\]]*\\]\\([^)]+\\))', + '|(? { - // 组合正则:按优先级从左到右 - const INLINE_RE = new RegExp([ - // 图片 ![...](...) - '(!\\[[^\\]]*\\]\\([^)]+\\))', - // 链接 [...](...) - 需要忽略图片前缀 - '|(?