textpattern.js
2.6 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(function() {
module("tinymce.plugins.TextPattern", {
setupModule: function() {
QUnit.stop();
tinymce.init({
selector: 'textarea',
add_unload_trigger: false,
skin: false,
indent: false,
plugins: "textpattern",
init_instance_callback: function(ed) {
window.editor = ed;
QUnit.start();
}
});
},
teardown: function() {
delete editor.settings.textpattern_patterns;
}
});
test('Italic format on single word using space', function() {
editor.setContent('<p>*abc*\u00a0</p>');
Utils.setSelection('p', 6);
editor.fire('keyup', {keyCode: 32});
equal(
editor.getContent(),
'<p><em>abc</em> </p>'
);
});
test('Bold format on single word using space', function() {
editor.setContent('<p>**abc**\u00a0</p>');
Utils.setSelection('p', 8);
editor.fire('keyup', {keyCode: 32});
equal(
editor.getContent(),
'<p><strong>abc</strong> </p>'
);
});
test('Bold format on multiple words using space', function() {
editor.setContent('<p>**abc 123**\u00a0</p>');
Utils.setSelection('p', 12);
editor.fire('keyup', {keyCode: 32});
equal(
editor.getContent(),
'<p><strong>abc 123</strong> </p>'
);
});
test('Bold format on single word using enter', function() {
editor.setContent('<p>**abc**</p>');
Utils.setSelection('p', 7);
editor.fire('keydown', {keyCode: 13});
equal(
editor.getContent(),
'<p><strong>abc</strong></p><p> </p>'
);
});
test('H1 format on single word node using enter', function() {
editor.setContent('<p>#abc</p>');
Utils.setSelection('p', 4);
editor.fire('keydown', {keyCode: 13});
equal(
editor.getContent(),
'<h1>abc</h1><p> </p>'
);
});
test('OL format on single word node using enter', function() {
editor.setContent('<p>1. abc</p>');
Utils.setSelection('p', 6);
editor.fire('keydown', {keyCode: 13});
equal(
editor.getContent(),
'<ol><li>abc</li><li></li></ol>'
);
});
test('UL format on single word node using enter', function() {
editor.setContent('<p>* abc</p>');
Utils.setSelection('p', 5);
editor.fire('keydown', {keyCode: 13});
equal(
editor.getContent(),
'<ul><li>abc</li><li></li></ul>'
);
});
test('getPatterns/setPatterns', function() {
editor.plugins.textpattern.setPatterns([
{start: '#', format: 'h1'},
{start: '##', format: 'h2'},
{start: '###', format: 'h3'}
]);
deepEqual(
editor.plugins.textpattern.getPatterns(),
[
{
"format": "h3",
"start": "###"
},
{
"format": "h2",
"start": "##"
},
{
"format": "h1",
"start": "#"
}
]
);
});
})();