blob: 2183e1744cc356046d1da00b127c600b68285764 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import { createEditor } from './../EditorFactory'
import { createMarkdownSerializer } from './../extensions/Markdown'
import markdownit from './../markdownit'
import input from './fixtures/table.md'
import output from './fixtures/tables/basic.out.html'
import otherStructure from './fixtures/tableWithOtherStructure.html'
import handbook from './fixtures/tables/handbook.html'
import handbookOut from './fixtures/tables/handbook.out.html'
describe('Table', () => {
test('load into editor', () => {
const tiptap = editorWithContent(markdownit.render(input))
expect(formatHTML(tiptap.getHTML())).toBe(formatHTML(output))
})
test('serialize from editor', () => {
const tiptap = editorWithContent(markdownit.render(input))
const serializer = createMarkdownSerializer(tiptap.schema)
expect(serializer.serialize(tiptap.state.doc)).toBe(input)
})
test('handle html table with other structure', () => {
const tiptap = editorWithContent(
otherStructure.replace(/\n\s*/g,'')
)
expect(formatHTML(tiptap.getHTML())).toBe(formatHTML(output))
})
test('handle html table from handbook', () => {
const tiptap = editorWithContent(
handbook.replace(/\n\s*/g,'')
)
expect(formatHTML(tiptap.getHTML())).toBe(formatHTML(handbookOut))
})
})
function editorWithContent(content) {
return createEditor({
content,
enableRichEditing: true
})
}
function formatHTML(html) {
return html.replaceAll('><', ">\n<").replace(/\n$/, '')
}
|