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
49
50
51
52
53
54
55
56
57
58
59
|
import { Markdown } from './../../extensions';
import { createMarkdownSerializer } from './../../extensions/Markdown';
import Underline from './../../marks/Underline';
import { BulletList, ListItem } from './../../nodes'
import Image from '@tiptap/extension-image'
import { getExtensionField } from '@tiptap/core'
import createEditor from './../createEditor'
describe('Markdown extension unit', () => {
it('has a config', () => {
expect(Markdown.config.name).toBe('markdown')
})
it('exposes toMarkdown function in Prosemirror', () => {
const extend = getExtensionField(Markdown, 'extendMarkSchema', Markdown)
expect(extend(Underline).toMarkdown).toBeDefined()
})
it('makes toMarkdown available in prose mirror schema', () => {
const editor = createEditor({
extensions: [Markdown, Underline]
})
const serializer = createMarkdownSerializer(editor.schema)
const underline = serializer.serializer.marks.underline
expect(underline).toEqual(Underline.config.toMarkdown)
const listItem = serializer.serializer.nodes.listItem
expect(typeof listItem).toBe('function')
})
})
describe('Markdown extension integrated in the editor', () => {
it('serializes marks according to their spec', () => {
const editor = createEditor({
content: '<p><u>Test</u></p>',
extensions: [Markdown, Underline],
})
const serializer = createMarkdownSerializer(editor.schema)
expect(serializer.serialize(editor.state.doc)).toBe('__Test__')
})
it('serializes nodes according to their spec', () => {
const editor = createEditor({
content: '<p><ul><li>Hello</li></ul></p>',
extensions: [Markdown, BulletList, ListItem],
})
const serializer = createMarkdownSerializer(editor.schema)
expect(serializer.serialize(editor.state.doc)).toBe('\n* Hello')
})
it('serializes nodes with the default prosemirror way', () => {
const editor = createEditor({
content: `<p><img alt="Hello" src="test" /></p>`,
extensions: [Markdown, Image.configure({inline: true})],
})
const serializer = createMarkdownSerializer(editor.schema)
expect(serializer.serialize(editor.state.doc)).toBe('![Hello](test)')
})
})
|