fix: 粘贴时丢失内容
This commit is contained in:
parent
ffd663f2de
commit
d159844a06
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>wangEditor example</title>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>
|
||||
wangEditor demo
|
||||
</p>
|
||||
<div id="div1">
|
||||
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
|
||||
</div>
|
||||
|
||||
<script src="../dist/wangEditor.js"></script>
|
||||
<script>
|
||||
const E = window.wangEditor
|
||||
const editor = new E('#div1')
|
||||
editor.config.height = 800
|
||||
|
||||
// 过滤样式,默认 true
|
||||
editor.config.pasteFilterStyle = true
|
||||
|
||||
// 忽略图片,默认 false
|
||||
editor.config.pasteIgnoreImg = false
|
||||
|
||||
editor.config.pasteTextHandle = function (content) {
|
||||
return content
|
||||
}
|
||||
|
||||
editor.create()
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -94,14 +94,14 @@ function parseHtml(html: string, filterStyle: boolean = true, ignoreImg: boolean
|
|||
const htmlParser = new HtmlParser()
|
||||
htmlParser.parse(html, {
|
||||
startElement(tag: string, attrs: []) {
|
||||
// 首先,标记开始
|
||||
markTagStart(tag)
|
||||
|
||||
// 忽略的标签
|
||||
if (isIgnoreTag(tag, ignoreImg)) {
|
||||
return
|
||||
}
|
||||
|
||||
// 首先,标记开始
|
||||
markTagStart(tag)
|
||||
|
||||
// 找出该标签必须的属性(其他的属性忽略)
|
||||
const necessaryAttrKeys = NECESSARY_ATTRS.get(tag) || []
|
||||
const attrsForTag: AttrType[] = []
|
||||
|
@ -134,7 +134,10 @@ function parseHtml(html: string, filterStyle: boolean = true, ignoreImg: boolean
|
|||
str = str.trim()
|
||||
if (!str) return
|
||||
|
||||
if (!CUR_TAG) return // 如果当前没有标签,即纯文本,则忽略
|
||||
// 忽略的标签
|
||||
if (isIgnoreTag(CUR_TAG, ignoreImg)) {
|
||||
return
|
||||
}
|
||||
|
||||
resultArr.push(str)
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue