From 5aafcdc5a5e871102c50db9a9a95dc407e3cb2f1 Mon Sep 17 00:00:00 2001 From: Benature Date: Thu, 14 Mar 2024 15:02:00 +0800 Subject: [PATCH] [fix] `customReplace()`: error when search contains like `\.\!\?` --- CHANGELOG.md | 1 + src/format.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a033c99..18ccd1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## 🏗️ developed > to be updated in the next version +- [fix] `customReplace()`: error when search contains like `\.\!\?` - [updated] `Chinese-punctuation`: select modification at last - [updated] `math mode`: - calculation support `=` and Greek letters diff --git a/src/format.ts b/src/format.ts index 2cec48e..d95daf3 100644 --- a/src/format.ts +++ b/src/format.ts @@ -518,7 +518,8 @@ export function extraDoubleSpaces(editor: Editor, view: MarkdownView): void { export function customReplace(text: string, s: customReplaceSetting): string { s.data.forEach(data => { - text = text.replace(new RegExp(JSON.parse(`"${data.search}"`), "g"), JSON.parse(`"${data.replace}"`)) + const re = new RegExp(data.search, "g"); + text = text.replace(re, JSON.parse(`"${data.replace}"`)) }) return text; }