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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import { markdownit, createEditor, createMarkdownSerializer } from './../EditorFactory';
import spec from "./fixtures/spec"
const markdownToDocument = (markdown) => {
const tiptap = createEditor({
content: markdownit.render(markdown)
})
const serializer = createMarkdownSerializer(tiptap.nodes, tiptap.marks)
return tiptap.state.doc
}
const documentToMarkdown = (document) => {
const tiptap = createEditor({
content: document
})
const serializer = createMarkdownSerializer(tiptap.nodes, tiptap.marks)
const markdown = serializer.serialize(document)
}
const markdownThroughEditor = (markdown) => {
const tiptap = createEditor({
content: markdownit.render(markdown)
})
const serializer = createMarkdownSerializer(tiptap.nodes, tiptap.marks)
return serializer.serialize(tiptap.state.doc)
}
const markdownThroughEditorHtml = (html) => {
const tiptap = createEditor({
content: html
})
const serializer = createMarkdownSerializer(tiptap.nodes, tiptap.marks)
return serializer.serialize(tiptap.state.doc)
}
describe('Commonmark', () => {
beforeAll(() => {
// Make sure html tests pass
// entry.section === 'HTML blocks' || entry.section === 'Raw HTML'
markdownit.set({ html: true})
})
afterAll(() => {
markdownit.set({ html: false})
})
// failures because of some additional newline in markdownit
const skippedMarkdownTests = [
181, 202, 203
];
spec.forEach((entry) => {
if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
return
}
test('commonmark ' + entry.example, () => {
expect(markdownit.render(entry.markdown)).toBe(entry.html, entry)
})
})
})
describe('Markdown though editor', () => {
test('headlines', () => {
expect(markdownThroughEditor('# Test')).toBe('# Test')
expect(markdownThroughEditor('## Test')).toBe('## Test')
expect(markdownThroughEditor('### Test')).toBe('### Test')
expect(markdownThroughEditor('#### Test')).toBe('#### Test')
expect(markdownThroughEditor('##### Test')).toBe('##### Test')
})
test('inline format', () => {
expect(markdownThroughEditor('**Test**')).toBe('**Test**')
expect(markdownThroughEditor('__Test__')).toBe('**Test**')
expect(markdownThroughEditor('_Test_')).toBe('*Test*')
expect(markdownThroughEditor('~~Test~~')).toBe('~~Test~~')
})
test('ul', () => {
expect(markdownThroughEditor('- foo\n- bar')).toBe('* foo\n\n* bar')
expect(markdownThroughEditor('- foo\n\n- bar')).toBe('* foo\n\n* bar')
expect(markdownThroughEditor('- foo\n\n\n- bar')).toBe('* foo\n\n* bar')
})
test('ol', () => {
expect(markdownThroughEditor('1. foo\n2. bar')).toBe('1. foo\n\n2. bar')
})
test('paragraph', () => {
expect(markdownThroughEditor('foo\nbar\n\nfoobar\n\tfoobar')).toBe('foo bar\n\nfoobar foobar')
})
test('links', () => {
expect(markdownThroughEditor('[test](foo)')).toBe('[test](foo)')
})
test('images', () => {
expect(markdownThroughEditor('![test](foo)')).toBe('![test](foo)')
})
})
describe('Markdown serializer from html', () => {
test('paragraph', () => {
expect(markdownThroughEditorHtml('<p>hello</p><p>world</p>')).toBe('hello\n\nworld')
})
test('links', () => {
expect(markdownThroughEditorHtml('<a href="foo">test</a>')).toBe('[test](foo)')
})
test('images', () => {
expect(markdownThroughEditorHtml('<img src="image" alt="description" />')).toBe('![description](image)')
})
})
|