fix: txt.html()获取的内容中将没有自闭和的标签输出为自闭和标签
This commit is contained in:
parent
af732713bb
commit
57690447ed
|
@ -19,12 +19,14 @@
|
||||||
<img src="http://www.wangeditor.com/imgs/logo.jpeg" />
|
<img src="http://www.wangeditor.com/imgs/logo.jpeg" />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<button id="btn">获取html内容</button>
|
||||||
|
|
||||||
<script src="../dist/wangEditor.js"></script>
|
<script src="../dist/wangEditor.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// 改为使用var声明,才能在window对象上获取到编辑器实例,方便e2e测试
|
// 改为使用var声明,才能在window对象上获取到编辑器实例,方便e2e测试
|
||||||
var E = window.wangEditor
|
var E = window.wangEditor
|
||||||
var editor = new E('#div1')
|
var editor = new E('#div1')
|
||||||
|
editor.config.uploadImgServer = '/api/upload-img'
|
||||||
|
|
||||||
editor.config.onchange = function (newHtml) {
|
editor.config.onchange = function (newHtml) {
|
||||||
console.log('onchange', newHtml)
|
console.log('onchange', newHtml)
|
||||||
|
@ -33,6 +35,9 @@
|
||||||
editor.config.showFullScreen = true
|
editor.config.showFullScreen = true
|
||||||
editor.create()
|
editor.create()
|
||||||
editor.txt.html("<p>123</p><p>456</p>")
|
editor.txt.html("<p>123</p><p>456</p>")
|
||||||
|
document.getElementById('btn').onclick = function () {
|
||||||
|
console.log(editor.txt.html())
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,15 @@ class Text {
|
||||||
*/
|
*/
|
||||||
// html = formatCodeHtml(editor, html)
|
// html = formatCodeHtml(editor, html)
|
||||||
|
|
||||||
|
// 将没有自闭和的标签过滤为自闭和
|
||||||
|
const selfCloseHtmls: RegExpMatchArray | null = html.match(/<(img|br|hr|input)[^>]*>/gi)
|
||||||
|
if (selfCloseHtmls !== null) {
|
||||||
|
selfCloseHtmls.forEach(item => {
|
||||||
|
if (!item.match(/\/>/)) {
|
||||||
|
html = html.replace(item, item.substring(0, item.length - 1) + '/>')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
return html
|
return html
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ describe('split-line menu', () => {
|
||||||
|
|
||||||
splitLineMenu.clickHandler()
|
splitLineMenu.clickHandler()
|
||||||
|
|
||||||
expect((editor.txt.html() as string).indexOf('<hr>')).toBeGreaterThanOrEqual(0)
|
expect((editor.txt.html() as string).indexOf('<hr/>')).toBeGreaterThanOrEqual(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('执行 splitLineEvents 里面的钩子函数会展示 tooltip 菜单,点击其它地方会隐藏tooptip', () => {
|
test('执行 splitLineEvents 里面的钩子函数会展示 tooltip 菜单,点击其它地方会隐藏tooptip', () => {
|
||||||
|
@ -52,7 +52,7 @@ describe('split-line menu', () => {
|
||||||
|
|
||||||
splitLineMenu.clickHandler()
|
splitLineMenu.clickHandler()
|
||||||
|
|
||||||
expect((editor.txt.html() as string).indexOf('<hr>')).toBeGreaterThanOrEqual(0)
|
expect((editor.txt.html() as string).indexOf('<hr/>')).toBeGreaterThanOrEqual(0)
|
||||||
|
|
||||||
editor.txt.eventHooks.splitLineEvents.forEach(fn => {
|
editor.txt.eventHooks.splitLineEvents.forEach(fn => {
|
||||||
fn(splitLineMenu.$elem)
|
fn(splitLineMenu.$elem)
|
||||||
|
|
|
@ -9,7 +9,7 @@ editor.txt.append('<p>abc</p><p>test</p>')
|
||||||
test('设置todo功能', () => {
|
test('设置todo功能', () => {
|
||||||
boldMenu.clickHandler()
|
boldMenu.clickHandler()
|
||||||
expect(editor.txt.html()).toEqual(
|
expect(editor.txt.html()).toEqual(
|
||||||
`<p>abc</p><ul class="w-e-todo"><li><span contenteditable="false"><input type="checkbox"></span>test</li></ul>`
|
`<p>abc</p><ul class="w-e-todo"><li><span contenteditable="false"><input type="checkbox"/></span>test</li></ul>`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -23,6 +23,6 @@ test('在第一行设置todo', () => {
|
||||||
const boldMenu = getMenuInstance(editor, todo)
|
const boldMenu = getMenuInstance(editor, todo)
|
||||||
boldMenu.clickHandler()
|
boldMenu.clickHandler()
|
||||||
expect(editor.txt.html()).toEqual(
|
expect(editor.txt.html()).toEqual(
|
||||||
'<ul class="w-e-todo"><li><span contenteditable="false"><input type="checkbox"></span><br></li></ul>'
|
'<ul class="w-e-todo"><li><span contenteditable="false"><input type="checkbox"/></span><br/></li></ul>'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue