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
|
import { createEditor, serializePlainText } from './../EditorFactory';
import spec from "./fixtures/spec"
import xssFuzzVectors from './fixtures/xssFuzzVectors';
const escapeHTML = (s) => {
return s.toString()
.split('&').join('&')
.split('<').join('<')
.split('>').join('>')
.split('"').join('"')
.split('\'').join(''')
}
const plaintextThroughEditor = (markdown) => {
const content = '<pre>' + escapeHTML(markdown) + '</pre>'
const tiptap = createEditor({
content: content,
enableRichEditing: false
})
return serializePlainText(tiptap) || 'failed'
}
describe('commonmark as plaintext', () => {
// FIXME: Those two tests currently fail as trailing whitespace seems to be stripped,
// if it occurs in the first line which is empty otherwise.
const skippedMarkdownTests = [
67, 87
];
spec.forEach((entry) => {
if (skippedMarkdownTests.indexOf(entry.example) !== -1) {
return
}
test('commonmark ' + entry.example, () => {
expect(plaintextThroughEditor(entry.markdown)).toBe(entry.markdown)
})
})
})
describe('markdown as plaintext', () => {
test('headlines', () => {
expect(plaintextThroughEditor('# Test')).toBe('# Test')
expect(plaintextThroughEditor('## Test')).toBe('## Test')
expect(plaintextThroughEditor('### Test')).toBe('### Test')
expect(plaintextThroughEditor('#### Test')).toBe('#### Test')
expect(plaintextThroughEditor('##### Test')).toBe('##### Test')
})
test('inline format', () => {
expect(plaintextThroughEditor('**Test**')).toBe('**Test**')
expect(plaintextThroughEditor('__Test__')).toBe('__Test__')
expect(plaintextThroughEditor('_Test_')).toBe('_Test_')
expect(plaintextThroughEditor('~~Test~~')).toBe('~~Test~~')
})
test('ul', () => {
expect(plaintextThroughEditor('- foo\n- bar')).toBe('- foo\n- bar')
expect(plaintextThroughEditor('- foo\n\n- bar')).toBe('- foo\n\n- bar')
expect(plaintextThroughEditor('- foo\n\n\n- bar')).toBe('- foo\n\n\n- bar')
})
test('ol', () => {
expect(plaintextThroughEditor('1. foo\n2. bar')).toBe('1. foo\n2. bar')
})
test('paragraph', () => {
expect(plaintextThroughEditor('foo\nbar\n\nfoobar\n\tfoobar')).toBe('foo\nbar\n\nfoobar\n\tfoobar')
})
test('links', () => {
expect(plaintextThroughEditor('[test](foo)')).toBe('[test](foo)')
})
test('images', () => {
expect(plaintextThroughEditor('![test](foo)')).toBe('![test](foo)')
})
})
describe('html as plain text', () => {
test('link', () => {
expect(plaintextThroughEditor('<a>sdf</a>')).toBe('<a>sdf</a>')
expect(plaintextThroughEditor('<a href="foobar">sdf</a>')).toBe('<a href="foobar">sdf</a>')
})
test('special characters', () => {
expect(plaintextThroughEditor('"\';&.-#><')).toBe('"\';&.-#><')
expect(plaintextThroughEditor(xssFuzzVectors)).toBe(xssFuzzVectors)
})
})
|