From 1e75ff247de867d14f6c6b634f671ce1d943ff84 Mon Sep 17 00:00:00 2001 From: Moy Date: Mon, 15 Sep 2025 11:52:24 +0800 Subject: [PATCH] feat(parser): support _ and __ markup and fix capture selection Closes #16 --- src/main.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0548a73..5d9448d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -248,14 +248,15 @@ export default class EasyCopy extends Plugin { // iOS 16.4 之前不支持后视(Lookbehinds),但支持前视(Lookaheads) // 所以针对 iOS 平台使用只带前视的正则表达式,其他平台使用完整版本 const italicRegex = Platform.isIosApp ? - /\*([^*]+)\*(?!\*)/g : // iOS 版本:只使用前视,不使用后视 - /(? 斜体 > 高亮 > 删除线 > 行内代码 > 行内Latex > 块ID > 双链 const matchers = [ - { type: ContextType.BOLD, regex: /\*\*([^*]+)\*\*/g , enable: !this.settings.customizeTargets || this.settings.enableBold}, - // 使用前后断言 (?= matchStart && beforeCursor.length <= matchEnd) { + // 找到第一个非空且非整体匹配的捕获组作为内容 + let content = ''; + for (let i = 1; i < match.length; i++) { + if (match[i] !== undefined) { + content = match[i]; + break; + } + } + return { - content: match[1], // 返回内容,不包括语法 + content: content, // 返回内容,不包括语法 range: [matchStart, matchEnd], }; }