由于某些旧版本的 iOS 不支持 lookbehind,在这个替代方案中,(^|[^*]) 确保在星号前面是字符串的开始或不是星号的字符。这样可以避免使用 lookbehind,同时实现相同的匹配效果。

This commit is contained in:
naive231 2024-11-21 14:03:35 +08:00
parent 426aa5af20
commit 3736f2a192
1 changed files with 1 additions and 1 deletions

View File

@ -177,7 +177,7 @@ function applyFormatting(text: string): string {
// Define the patterns and their replacements in order
const patterns = [
{ regex: /\*\*(.*?)\*\*/, replacement: ' *$1* ' }, // bold
{ regex: /(?<!\*)\*(?!\*)(.*?)\*(?!\*)/, replacement: ' _$1_ ' }, // italic
{ regex: /(^|[^*])\*(.*?)\*(?!\*)/, replacement: '$1_$2_' }, // italic
{ regex: /~~(.*?)~~/, replacement: ' ~$1~ ' }, // strike
{ regex: /==(.*?)==/, replacement: ' `$1` ' }, // emphasize
{ regex: /`(.*?)`/, replacement: ' {$1} ' }, // quote