由于某些旧版本的 iOS 不支持 lookbehind,在这个替代方案中,(^|[^*]) 确保在星号前面是字符串的开始或不是星号的字符。这样可以避免使用 lookbehind,同时实现相同的匹配效果。
This commit is contained in:
parent
426aa5af20
commit
3736f2a192
2
main.ts
2
main.ts
|
@ -177,7 +177,7 @@ function applyFormatting(text: string): string {
|
||||||
// Define the patterns and their replacements in order
|
// Define the patterns and their replacements in order
|
||||||
const patterns = [
|
const patterns = [
|
||||||
{ regex: /\*\*(.*?)\*\*/, replacement: ' *$1* ' }, // bold
|
{ regex: /\*\*(.*?)\*\*/, replacement: ' *$1* ' }, // bold
|
||||||
{ regex: /(?<!\*)\*(?!\*)(.*?)\*(?!\*)/, replacement: ' _$1_ ' }, // italic
|
{ regex: /(^|[^*])\*(.*?)\*(?!\*)/, replacement: '$1_$2_' }, // italic
|
||||||
{ regex: /~~(.*?)~~/, replacement: ' ~$1~ ' }, // strike
|
{ regex: /~~(.*?)~~/, replacement: ' ~$1~ ' }, // strike
|
||||||
{ regex: /==(.*?)==/, replacement: ' `$1` ' }, // emphasize
|
{ regex: /==(.*?)==/, replacement: ' `$1` ' }, // emphasize
|
||||||
{ regex: /`(.*?)`/, replacement: ' {$1} ' }, // quote
|
{ regex: /`(.*?)`/, replacement: ' {$1} ' }, // quote
|
||||||
|
|
Loading…
Reference in New Issue