修复markd 混合html时段落解析异常的bug

master
yutent 2023-04-28 10:51:20 +08:00
parent b9a01d11ff
commit d9a3bcc262
1 changed files with 11 additions and 11 deletions

View File

@ -13,7 +13,6 @@ const TAG_RE = /<([\w\-]+)([\w\W]*?)>/g
const ATTR_RE = /\s*?on[a-zA-Z]+="[^"]*?"\s*?/g const ATTR_RE = /\s*?on[a-zA-Z]+="[^"]*?"\s*?/g
const CODEBLOCK_RE = /```(.*?)([\w\W]*?)```/g const CODEBLOCK_RE = /```(.*?)([\w\W]*?)```/g
const BLOCK_RE = /<([\w\-]+)([^>]*?)>([\w\W]*?)<\/\1>/g const BLOCK_RE = /<([\w\-]+)([^>]*?)>([\w\W]*?)<\/\1>/g
const IS_DOM_RE = /^<([\w\-]+)[^>]*?>.*?<\/\1>$/
const STYLE_RE = /<style[^>]*?>([\w\W]*?)<\/style>/g const STYLE_RE = /<style[^>]*?>([\w\W]*?)<\/style>/g
const SINGLE_LINE_HTML_RE = /^\s*?<([\w\-]+)[^>]*?>.*?<\/\1>\s*?$/ const SINGLE_LINE_HTML_RE = /^\s*?<([\w\-]+)[^>]*?>.*?<\/\1>\s*?$/
const MULTI_LINE_HTML_RE = /^\s*?<\/?[^>]*?>/ const MULTI_LINE_HTML_RE = /^\s*?<\/?[^>]*?>/
@ -74,10 +73,6 @@ const Helper = {
}, },
isTable(str) { isTable(str) {
return /^\|.+?\|$/.test(str) return /^\|.+?\|$/.test(str)
},
// 是否原生dom节点
isNativeDom(str) {
return IS_DOM_RE.test(str)
} }
} }
@ -293,6 +288,7 @@ class Tool {
html += it html += it
isTable = !isTable isTable = !isTable
tableAlign = true tableAlign = true
isHtmlBlock = false
continue continue
} }
@ -334,6 +330,7 @@ class Tool {
} }
html += it html += it
isCodeBlock = !isCodeBlock isCodeBlock = !isCodeBlock
isHtmlBlock = false
continue continue
} }
@ -382,7 +379,7 @@ class Tool {
} }
isList = false isList = false
} }
isHtmlBlock = false
html += head html += head
continue continue
} }
@ -451,6 +448,7 @@ class Tool {
html += it html += it
} }
isHtmlBlock = false
isParagraph = false isParagraph = false
isBlockquote = true isBlockquote = true
continue continue
@ -460,6 +458,7 @@ class Tool {
let task = Decoder.task(it) let task = Decoder.task(it)
if (task) { if (task) {
html += task html += task
isHtmlBlock = false
continue continue
} }
@ -473,6 +472,11 @@ class Tool {
let level = Math.floor(ltrim / 2) //缩进级别 let level = Math.floor(ltrim / 2) //缩进级别
let tag = listChecked === 1 ? 'ol' : 'ul' let tag = listChecked === 1 ? 'ol' : 'ul'
if (isParagraph) {
isParagraph = false
html += '</p>\n'
}
if (isList) { if (isList) {
let _level = listChecked === 1 ? orderListLevel : unorderListLevel let _level = listChecked === 1 ? orderListLevel : unorderListLevel
@ -507,6 +511,7 @@ class Tool {
} }
isList = true isList = true
isHtmlBlock = false
continue continue
} }
@ -516,11 +521,6 @@ class Tool {
continue continue
} }
if (Helper.isNativeDom(it)) {
html += it
continue
}
if (isHtmlBlock || isSingleLineHtml) { if (isHtmlBlock || isSingleLineHtml) {
if (isParagraph) { if (isParagraph) {
isParagraph = false isParagraph = false