forked from forgeworks/quill-delta-python
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_html.py
221 lines (188 loc) · 6.28 KB
/
test_html.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from delta import html
from delta.base import Delta
def test_basics():
ops = [
{ "insert":"Quill\nEditor\n\n" },
{ "insert": "bold",
"attributes": {"bold": True}},
{ "insert":" and the " },
{ "insert":"italic",
"attributes": { "italic": True }},
{ "insert":"\n\nNormal\n" },
]
source = '<p>Quill</p><p>Editor</p><p><br></p><p><strong>bold</strong> and the <em>italic</em></p><p><br></p><p>Normal</p>'
assert html.render(ops) == source
def test_empty():
ops = [ {"insert": "\n"} ]
source = "<p><br></p>"
assert html.render(ops) == source
def test_link():
ops = [
{ 'insert': "example.com", "attributes": {"link": "http://example.com"} }
]
source = '<p><a href="http://example.com">example.com</a></p>'
assert html.render(ops) == source
def test_video():
ops = [
{"insert":{"video":"https://www.youtube.com/embed/NAb9V08zcBE"}},
{"insert": "\n"}
]
source = '<iframe class="ql-video" frameborder="0" allowfullscreen="true" src="https://www.youtube.com/embed/NAb9V08zcBE"></iframe><p><br></p>'
assert html.render(ops) == source
def test_colors():
ops = [
{"insert": "quill", "attributes": {"background": "#000000"}}
]
source = '<p><span style="background-color: #000">quill</span></p>'
assert html.render(ops) == source
ops = [
{"insert": "quill", "attributes": {"background": "#000000", "color": "#FFFFFF"}}
]
source = '<p><span style="background-color: #000; color: #FFF">quill</span></p>'
assert html.render(ops) == source
def test_classes():
ops = [
{"insert":"Quill", "attributes": {"font": "monospace", "size": "huge"}}
]
source = '<p><span class="ql-font-monospace ql-size-huge">Quill</span></p>'
assert html.render(ops) == source
ops = [
{"insert":"Quill", "attributes": {"font": "serif", "size": "large"}}
]
source = '<p><span class="ql-font-serif ql-size-large">Quill</span></p>'
assert html.render(ops) == source
ops = [
{"insert":"Quill", "attributes": {"font": "sans-serif", "size": "small"}}
]
source = '<p><span class="ql-size-small">Quill</span></p>'
assert html.render(ops) == source
def test_strong():
ops = [
{"insert":"Quill", "attributes": {"bold": True}}
]
source = '<p><strong>Quill</strong></p>'
assert html.render(ops) == source
ops = [
{"insert":"Quill", "attributes": {"strong": True}}
]
source = '<p><strong>Quill</strong></p>'
assert html.render(ops) == source
def test_em():
ops = [
{"insert":"Quill", "attributes": {"italic": True}}
]
source = '<p><em>Quill</em></p>'
assert html.render(ops) == source
ops = [
{"insert":"Quill", "attributes": {"em": True}}
]
source = '<p><em>Quill</em></p>'
assert html.render(ops) == source
def test_underline():
ops = [
{"insert":"Quill", "attributes": {"underline": True}}
]
source = '<p><u>Quill</u></p>'
assert html.render(ops) == source
def test_strike():
ops = [
{"insert":"Quill", "attributes": {"strike": True}}
]
source = '<p><s>Quill</s></p>'
assert html.render(ops) == source
def test_script():
ops = [
{"insert":"Quill", "attributes": {"script": "sub"}}
]
source = '<p><sub>Quill</sub></p>'
assert html.render(ops) == source
ops = [
{"insert":"Quill", "attributes": {"script": "super"}}
]
source = '<p><sup>Quill</sup></p>'
assert html.render(ops) == source
def test_header():
ops = [
{"insert":"Quill", "attributes": {"header": 1}}
]
source = '<h1>Quill</h1>'
assert html.render(ops) == source
ops = [
{"insert":"Quill", "attributes": {"header": 5}}
]
source = '<h5>Quill</h5>'
assert html.render(ops) == source
ops = [
{"insert":"Quill"},
{"insert":"\n", "attributes": {"header": 2}}
]
source = '<h2>Quill</h2>'
assert html.render(ops) == source
def test_blockquote():
ops = [
{'insert': 'One\nTwo\nQuote'},
{'insert': '\n', 'attributes': {'blockquote': True}}
]
source = '<p>One</p><p>Two</p><blockquote>Quote</blockquote>'
assert html.render(ops) == source
def test_codeblock():
from delta.html import CODE_BLOCK_CLASS
ops = [
{"insert":"Quill", "attributes": {"code-block": True}}
]
source = '<pre class="%s" spellcheck="false">Quill</pre>' % CODE_BLOCK_CLASS
assert html.render(ops) == source
def test_lists():
ops = [
{"insert": "item 1"},
{"insert": "\n", "attributes": {"list":"ordered"}},
{"insert": "item 2"},
{"insert": "\n", "attributes": {"list": "ordered"}},
{"insert":"item 3"},
{"insert": "\n", "attributes": {"list": "ordered"}}
]
source = "<ol><li>item 1</li><li>item 2</li><li>item 3</li></ol>"
assert html.render(ops) == source
ops = [
{"insert": "item 1"},
{"insert": "\n", "attributes": {"list":"bullet"}},
{"insert": "item 2"},
{"insert": "\n", "attributes": {"list": "bullet"}},
{"insert":"item 3"},
{"insert": "\n", "attributes": {"list": "bullet"}}
]
source = "<ul><li>item 1</li><li>item 2</li><li>item 3</li></ul>"
assert html.render(ops) == source
def test_indent():
for i in range(1, 9):
ops = [
{"insert": "quill", "attributes": {"indent": i}}
]
source = '<p class="ql-indent-%d">quill</p>' % i
assert html.render(ops) == source
def test_direction():
ops = [
{"insert": "quill"},
{"insert": "\n", "attributes": {"direction": "rtl"}}
]
source = '<p class="ql-direction-rtl">quill</p>'
assert html.render(ops) == source
def test_align():
ops = [
{"insert": "quill"},
{"insert": "\n", "attributes": {"align": "center"}}
]
source = '<p class="ql-align-center">quill</p>'
assert html.render(ops) == source
def test_image():
ops = [
{ 'insert': {'image': 'https://i.imgur.com/ZMSUFEU.gif'} }
]
source = '<p><img src="https://i.imgur.com/ZMSUFEU.gif"></p>'
assert html.render(ops) == source
def test_error():
ops = [
{ 'insert': {'image': True} }
]
source = '<p><img></p>'
assert html.render(ops) == source