Skip to content

Commit

Permalink
fix: compatible with more HTML styles
Browse files Browse the repository at this point in the history
  • Loading branch information
cycleccc committed Oct 23, 2024
1 parent c4dcfe2 commit 3adbb39
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 44 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/create/create-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { withHistory } from 'slate-history'

import { genEditorConfig } from '../config/index'
import { IEditorConfig } from '../config/interface'
import { DomEditor } from '../editor/dom-editor'
import { IDomEditor } from '../editor/interface'
import { withConfig } from '../editor/plugins/with-config'
import { withContent } from '../editor/plugins/with-content'
Expand Down Expand Up @@ -85,7 +84,7 @@ export default function (option: Partial<ICreateOption>) {
if (editor.children.length === 0) {
editor.children = genDefaultContent() // 默认内容
}
DomEditor.normalizeContent(editor) // 格式化,用户输入的 content 可能不规范(如两个相连的 text 没有合并)
// DomEditor.normalizeContent(editor) // 格式化,用户输入的 content 可能不规范(如两个相连的 text 没有合并)

if (selector) {
// 传入了 selector ,则创建 textarea DOM
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/parse-html/parse-elem-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Descendant } from 'slate'

import { IDomEditor } from '../editor/interface'
import { PRE_PARSE_HTML_CONF_LIST, TEXT_TAGS } from '../index'
import { getTagName } from '../utils/dom'
import { getTagName, NodeType } from '../utils/dom'
import parseCommonElemHtml from './parse-common-elem-html'
import parseTextElemHtml from './parse-text-elem-html'

Expand Down Expand Up @@ -41,6 +41,7 @@ function parseElemHtml($elem: Dom7Array, editor: IDomEditor): Descendant | Desce
return Array.from(childNodes).map(child => {
const $childElem = $(child)

if ($childElem[0].nodeType === NodeType.TEXT_NODE) { return { text: $childElem[0].textContent || '' } }
return parseTextElemHtml($childElem, editor)
})
}
Expand Down
19 changes: 0 additions & 19 deletions packages/list-module/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,4 @@ describe('list plugin test', () => {
editor.insertBreak()
expect(editor.children).toEqual([{ type: 'paragraph', children: [{ text: '' }] }])
})

it('兼容之前的 JSON 格式', () => {
const listItem = { type: 'list-item', children: [{ text: 'hello' }] }
let editor = createEditor({
// 之前的 JSON 格式
content: [
{
type: 'bulleted-list',
children: [listItem],
},
],
})
const bulletedList = { type: 'bulleted-list', children: [listItem] }

editor = withList(editor) // 使用插件
editor.insertNode(bulletedList)

expect(editor.children).toEqual([listItem])
})
})
22 changes: 0 additions & 22 deletions packages/video-module/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,5 @@ describe('videoModule module', () => {

expect(fn).toBeCalled()
})

test('使用 withVideo 插件后,Editor 调用 normalizeNode 方法确保 Video 元素后面有 paragraph、block、header 等元素', () => {
const videoElem = {
type: 'video',
src: 'test.mp4',
children: [],
}
const editor = createEditor({
content: [videoElem],
})
const newEditor = withVideo(editor)

newEditor.normalizeNode([videoElem, [0]])
expect(newEditor.children).toEqual([
{
type: 'video',
src: 'test.mp4',
children: [{ text: '' }],
},
{ type: 'paragraph', children: [{ text: '' }] },
])
})
})
})

0 comments on commit 3adbb39

Please sign in to comment.