fix: mp-html 单~被解析为中划线的问题修复
This commit is contained in:
@@ -13,7 +13,26 @@ function Markdown (vm) {
|
||||
|
||||
Markdown.prototype.onUpdate = function (content) {
|
||||
if (this.vm.markdown) {
|
||||
return marked(content)
|
||||
// return marked(content)
|
||||
// 先处理内容,确保只有双波浪号才被解析为删除线
|
||||
// 使用临时占位符保护单个波浪号
|
||||
let processedContent = content;
|
||||
|
||||
// 1. 先保护双波浪号删除线语法
|
||||
processedContent = processedContent.replace(/~~([^~]+?)~~/g, '__STRIKETHROUGH_START__$1__STRIKETHROUGH_END__');
|
||||
|
||||
// 2. 将剩余的单个波浪号转换为HTML实体
|
||||
processedContent = processedContent.replace(/~/g, '~');
|
||||
|
||||
// 3. 恢复双波浪号删除线语法
|
||||
processedContent = processedContent.replace(/__STRIKETHROUGH_START__/g, '~~').replace(/__STRIKETHROUGH_END__/g, '~~');
|
||||
|
||||
return marked(processedContent, {
|
||||
gfm: true,
|
||||
breaks: false,
|
||||
pedantic: false,
|
||||
sanitize: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user