wysihtml5x-rails 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,649 @@
1
+ /**
2
+ * Full HTML5 compatibility rule set
3
+ * These rules define which tags and CSS classes are supported and which tags should be specially treated.
4
+ *
5
+ * Examples based on this rule set:
6
+ *
7
+ * <a href="http://foobar.com">foo</a>
8
+ * ... becomes ...
9
+ * <a href="http://foobar.com" target="_blank" rel="nofollow">foo</a>
10
+ *
11
+ * <img align="left" src="http://foobar.com/image.png">
12
+ * ... becomes ...
13
+ * <img class="wysiwyg-float-left" src="http://foobar.com/image.png" alt="">
14
+ *
15
+ * <div>foo<script>alert(document.cookie);</script></div>
16
+ * ... becomes ...
17
+ * <div>foo</div>
18
+ *
19
+ * <marquee>foo</marquee>
20
+ * ... becomes ...
21
+ * <span>foo</span>
22
+ *
23
+ * foo <br clear="both"> bar
24
+ * ... becomes ...
25
+ * foo <br class="wysiwyg-clear-both"> bar
26
+ *
27
+ * <div>hello <iframe src="http://google.com"></iframe></div>
28
+ * ... becomes ...
29
+ * <div>hello </div>
30
+ *
31
+ * <center>hello</center>
32
+ * ... becomes ...
33
+ * <div class="wysiwyg-text-align-center">hello</div>
34
+ */
35
+ var wysihtml5ParserRules = {
36
+ /**
37
+ * CSS Class white-list
38
+ * Following CSS classes won't be removed when parsed by the wysihtml5 HTML parser
39
+ */
40
+ "classes": {
41
+ "wysiwyg-clear-both": 1,
42
+ "wysiwyg-clear-left": 1,
43
+ "wysiwyg-clear-right": 1,
44
+ "wysiwyg-color-aqua": 1,
45
+ "wysiwyg-color-black": 1,
46
+ "wysiwyg-color-blue": 1,
47
+ "wysiwyg-color-fuchsia": 1,
48
+ "wysiwyg-color-gray": 1,
49
+ "wysiwyg-color-green": 1,
50
+ "wysiwyg-color-lime": 1,
51
+ "wysiwyg-color-maroon": 1,
52
+ "wysiwyg-color-navy": 1,
53
+ "wysiwyg-color-olive": 1,
54
+ "wysiwyg-color-purple": 1,
55
+ "wysiwyg-color-red": 1,
56
+ "wysiwyg-color-silver": 1,
57
+ "wysiwyg-color-teal": 1,
58
+ "wysiwyg-color-white": 1,
59
+ "wysiwyg-color-yellow": 1,
60
+ "wysiwyg-float-left": 1,
61
+ "wysiwyg-float-right": 1,
62
+ "wysiwyg-font-size-large": 1,
63
+ "wysiwyg-font-size-larger": 1,
64
+ "wysiwyg-font-size-medium": 1,
65
+ "wysiwyg-font-size-small": 1,
66
+ "wysiwyg-font-size-smaller": 1,
67
+ "wysiwyg-font-size-x-large": 1,
68
+ "wysiwyg-font-size-x-small": 1,
69
+ "wysiwyg-font-size-xx-large": 1,
70
+ "wysiwyg-font-size-xx-small": 1,
71
+ "wysiwyg-text-align-center": 1,
72
+ "wysiwyg-text-align-justify": 1,
73
+ "wysiwyg-text-align-left": 1,
74
+ "wysiwyg-text-align-right": 1
75
+ },
76
+
77
+
78
+ "type_definitions": {
79
+
80
+ "alignment_object": {
81
+ "classes": {
82
+ "wysiwyg-text-align-center": 1,
83
+ "wysiwyg-text-align-justify": 1,
84
+ "wysiwyg-text-align-left": 1,
85
+ "wysiwyg-text-align-right": 1,
86
+ "wysiwyg-float-left": 1,
87
+ "wysiwyg-float-right": 1
88
+ },
89
+ "styles": {
90
+ "float": ["left", "right"],
91
+ "textAlign": ["left", "right", "center"]
92
+ }
93
+ },
94
+
95
+ "valid_image_src": {
96
+ "attrs": {
97
+ "src": /^[^data\:]/i
98
+ }
99
+ },
100
+
101
+ "text_color_object": {
102
+ "styles": {
103
+ "color": true,
104
+ "background-color": true
105
+ }
106
+ },
107
+
108
+ "text_fontsize_object": {
109
+ "styles": {
110
+ "font-size": true
111
+ }
112
+ },
113
+
114
+ "text_formatting_object": {
115
+ "classes": {
116
+ "wysiwyg-color-aqua": 1,
117
+ "wysiwyg-color-black": 1,
118
+ "wysiwyg-color-blue": 1,
119
+ "wysiwyg-color-fuchsia": 1,
120
+ "wysiwyg-color-gray": 1,
121
+ "wysiwyg-color-green": 1,
122
+ "wysiwyg-color-lime": 1,
123
+ "wysiwyg-color-maroon": 1,
124
+ "wysiwyg-color-navy": 1,
125
+ "wysiwyg-color-olive": 1,
126
+ "wysiwyg-color-purple": 1,
127
+ "wysiwyg-color-red": 1,
128
+ "wysiwyg-color-silver": 1,
129
+ "wysiwyg-color-teal": 1,
130
+ "wysiwyg-color-white": 1,
131
+ "wysiwyg-color-yellow": 1,
132
+ "wysiwyg-font-size-large": 1,
133
+ "wysiwyg-font-size-larger": 1,
134
+ "wysiwyg-font-size-medium": 1,
135
+ "wysiwyg-font-size-small": 1,
136
+ "wysiwyg-font-size-smaller": 1,
137
+ "wysiwyg-font-size-x-large": 1,
138
+ "wysiwyg-font-size-x-small": 1,
139
+ "wysiwyg-font-size-xx-large": 1,
140
+ "wysiwyg-font-size-xx-small": 1
141
+ }
142
+ }
143
+ },
144
+
145
+ /**
146
+ * Tag list
147
+ *
148
+ * The following options are available:
149
+ *
150
+ * - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class
151
+ * The following methods are implemented in wysihtml5.dom.parse:
152
+ * - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")
153
+ * <p align="center">foo</p> ... becomes ... <p> class="wysiwyg-text-align-center">foo</p>
154
+ * - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*"
155
+ * <br clear="all"> ... becomes ... <br class="wysiwyg-clear-both">
156
+ * - align_img: converts align attribute values (right/left) on <img> to their corresponding css class "wysiwyg-float-*"
157
+ *
158
+ * - remove: removes the element and its content
159
+ *
160
+ * - unwrap removes element but leaves content
161
+ *
162
+ * - rename_tag: renames the element to the given tag
163
+ *
164
+ * - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above)
165
+ *
166
+ * - set_attributes: sets/overrides the given attributes
167
+ *
168
+ * - check_attributes: checks the given HTML attribute via the given method
169
+ * - url: allows only valid urls (starting with http:// or https://)
170
+ * - src: allows something like "/foobar.jpg", "http://google.com", ...
171
+ * - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg"
172
+ * - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML)
173
+ * - numbers: ensures that the attribute only contains numeric characters
174
+ */
175
+ "tags": {
176
+ "tr": {
177
+ "add_class": {
178
+ "align": "align_text"
179
+ }
180
+ },
181
+ "strike": {
182
+ "unwrap": 1
183
+ },
184
+ "form": {
185
+ "unwrap": 1
186
+ },
187
+ "rt": {
188
+ "rename_tag": "span"
189
+ },
190
+ "code": {},
191
+ "acronym": {
192
+ "rename_tag": "span"
193
+ },
194
+ "br": {
195
+ "add_class": {
196
+ "clear": "clear_br"
197
+ }
198
+ },
199
+ "details": {
200
+ "unwrap": 1
201
+ },
202
+ "h4": {
203
+ "add_class": {
204
+ "align": "align_text"
205
+ }
206
+ },
207
+ "em": {},
208
+ "title": {
209
+ "remove": 1
210
+ },
211
+ "multicol": {
212
+ "unwrap": 1
213
+ },
214
+ "figure": {
215
+ "unwrap": 1
216
+ },
217
+ "xmp": {
218
+ "unwrap": 1
219
+ },
220
+ "small": {
221
+ "rename_tag": "span",
222
+ "set_class": "wysiwyg-font-size-smaller"
223
+ },
224
+ "area": {
225
+ "remove": 1
226
+ },
227
+ "time": {
228
+ "unwrap": 1
229
+ },
230
+ "dir": {
231
+ "rename_tag": "ul"
232
+ },
233
+ "bdi": {
234
+ "unwrap": 1
235
+ },
236
+ "command": {
237
+ "unwrap": 1
238
+ },
239
+ "ul": {},
240
+ "progress": {
241
+ "rename_tag": "span"
242
+ },
243
+ "dfn": {
244
+ "unwrap": 1
245
+ },
246
+ "iframe": {
247
+ "remove": 1
248
+ },
249
+ "figcaption": {
250
+ "unwrap": 1
251
+ },
252
+ "a": {
253
+ "check_attributes": {
254
+ "href": "href" // if you compiled master manually then change this from 'url' to 'href'
255
+ },
256
+ "set_attributes": {
257
+ "rel": "nofollow",
258
+ "target": "_blank"
259
+ }
260
+ },
261
+ "img": {
262
+ "one_of_type": {
263
+ "valid_image_src": 1
264
+ },
265
+ "check_attributes": {
266
+ "width": "numbers",
267
+ "alt": "alt",
268
+ "src": "src", // if you compiled master manually then change this from 'url' to 'src'
269
+ "height": "numbers"
270
+ },
271
+ "add_class": {
272
+ "align": "align_img"
273
+ }
274
+ },
275
+ "rb": {
276
+ "unwrap": 1
277
+ },
278
+ "footer": {
279
+ "rename_tag": "div"
280
+ },
281
+ "noframes": {
282
+ "remove": 1
283
+ },
284
+ "abbr": {
285
+ "unwrap": 1
286
+ },
287
+ "u": {},
288
+ "bgsound": {
289
+ "remove": 1
290
+ },
291
+ "sup": {
292
+ "unwrap": 1
293
+ },
294
+ "address": {
295
+ "unwrap": 1
296
+ },
297
+ "basefont": {
298
+ "remove": 1
299
+ },
300
+ "nav": {
301
+ "unwrap": 1
302
+ },
303
+ "h1": {
304
+ "add_class": {
305
+ "align": "align_text"
306
+ }
307
+ },
308
+ "head": {
309
+ "unwrap": 1
310
+ },
311
+ "tbody": {
312
+ "add_class": {
313
+ "align": "align_text"
314
+ }
315
+ },
316
+ "dd": {
317
+ "unwrap": 1
318
+ },
319
+ "s": {
320
+ "unwrap": 1
321
+ },
322
+ "li": {},
323
+ "td": {
324
+ "check_attributes": {
325
+ "rowspan": "numbers",
326
+ "colspan": "numbers"
327
+ },
328
+ "add_class": {
329
+ "align": "align_text"
330
+ }
331
+ },
332
+ "object": {
333
+ "remove": 1
334
+ },
335
+
336
+ "div": {
337
+ "one_of_type": {
338
+ "alignment_object": 1,
339
+ },
340
+ "remove_action": "unwrap",
341
+ "keep_styles": {
342
+ "textAlign": 1,
343
+ "float": 1
344
+ },
345
+ "add_class": {
346
+ "align": "align_text"
347
+ }
348
+ },
349
+
350
+ "option": {
351
+ "remove":1
352
+ },
353
+ "select": {
354
+ "remove":1
355
+ },
356
+ "i": {},
357
+ "track": {
358
+ "remove": 1
359
+ },
360
+ "wbr": {
361
+ "remove": 1
362
+ },
363
+ "fieldset": {
364
+ "unwrap": 1
365
+ },
366
+ "big": {
367
+ "rename_tag": "span",
368
+ "set_class": "wysiwyg-font-size-larger"
369
+ },
370
+ "button": {
371
+ "unwrap": 1
372
+ },
373
+ "noscript": {
374
+ "remove": 1
375
+ },
376
+ "svg": {
377
+ "remove": 1
378
+ },
379
+ "input": {
380
+ "remove": 1
381
+ },
382
+ "table": {},
383
+ "keygen": {
384
+ "remove": 1
385
+ },
386
+ "h5": {
387
+ "add_class": {
388
+ "align": "align_text"
389
+ }
390
+ },
391
+ "meta": {
392
+ "remove": 1
393
+ },
394
+ "map": {
395
+ "remove": 1
396
+ },
397
+ "isindex": {
398
+ "remove": 1
399
+ },
400
+ "mark": {
401
+ "unwrap": 1
402
+ },
403
+ "caption": {
404
+ "add_class": {
405
+ "align": "align_text"
406
+ }
407
+ },
408
+ "tfoot": {
409
+ "add_class": {
410
+ "align": "align_text"
411
+ }
412
+ },
413
+ "base": {
414
+ "remove": 1
415
+ },
416
+ "video": {
417
+ "remove": 1
418
+ },
419
+ "strong": {},
420
+ "canvas": {
421
+ "remove": 1
422
+ },
423
+ "output": {
424
+ "unwrap": 1
425
+ },
426
+ "marquee": {
427
+ "unwrap": 1
428
+ },
429
+ "b": {},
430
+ "q": {
431
+ "check_attributes": {
432
+ "cite": "url"
433
+ }
434
+ },
435
+ "applet": {
436
+ "remove": 1
437
+ },
438
+ "span": {
439
+ "one_of_type": {
440
+ "text_formatting_object": 1,
441
+ "text_color_object": 1,
442
+ "text_fontsize_object": 1
443
+ },
444
+ "keep_styles": {
445
+ "color": 1,
446
+ "backgroundColor": 1,
447
+ "fontSize": 1
448
+ },
449
+ "remove_action": "unwrap"
450
+ },
451
+ "rp": {
452
+ "unwrap": 1
453
+ },
454
+ "spacer": {
455
+ "remove": 1
456
+ },
457
+ "source": {
458
+ "remove": 1
459
+ },
460
+ "aside": {
461
+ "rename_tag": "div"
462
+ },
463
+ "frame": {
464
+ "remove": 1
465
+ },
466
+ "section": {
467
+ "rename_tag": "div"
468
+ },
469
+ "body": {
470
+ "unwrap": 1
471
+ },
472
+ "ol": {},
473
+ "nobr": {
474
+ "unwrap": 1
475
+ },
476
+ "html": {
477
+ "unwrap": 1
478
+ },
479
+ "summary": {
480
+ "unwrap": 1
481
+ },
482
+ "var": {
483
+ "unwrap": 1
484
+ },
485
+ "del": {
486
+ "unwrap": 1
487
+ },
488
+ "blockquote": {
489
+ "check_attributes": {
490
+ "cite": "url"
491
+ }
492
+ },
493
+ "style": {
494
+ "remove": 1
495
+ },
496
+ "device": {
497
+ "remove": 1
498
+ },
499
+ "meter": {
500
+ "unwrap": 1
501
+ },
502
+ "h3": {
503
+ "add_class": {
504
+ "align": "align_text"
505
+ }
506
+ },
507
+ "textarea": {
508
+ "unwrap": 1
509
+ },
510
+ "embed": {
511
+ "remove": 1
512
+ },
513
+ "hgroup": {
514
+ "unwrap": 1
515
+ },
516
+ "font": {
517
+ "rename_tag": "span",
518
+ "add_class": {
519
+ "size": "size_font"
520
+ }
521
+ },
522
+ "tt": {
523
+ "unwrap": 1
524
+ },
525
+ "noembed": {
526
+ "remove": 1
527
+ },
528
+ "thead": {
529
+ "add_class": {
530
+ "align": "align_text"
531
+ }
532
+ },
533
+ "blink": {
534
+ "unwrap": 1
535
+ },
536
+ "plaintext": {
537
+ "unwrap": 1
538
+ },
539
+ "xml": {
540
+ "remove": 1
541
+ },
542
+ "h6": {
543
+ "add_class": {
544
+ "align": "align_text"
545
+ }
546
+ },
547
+ "param": {
548
+ "remove": 1
549
+ },
550
+ "th": {
551
+ "check_attributes": {
552
+ "rowspan": "numbers",
553
+ "colspan": "numbers"
554
+ },
555
+ "add_class": {
556
+ "align": "align_text"
557
+ }
558
+ },
559
+ "legend": {
560
+ "unwrap": 1
561
+ },
562
+ "hr": {},
563
+ "label": {
564
+ "unwrap": 1
565
+ },
566
+ "dl": {
567
+ "unwrap": 1
568
+ },
569
+ "kbd": {
570
+ "unwrap": 1
571
+ },
572
+ "listing": {
573
+ "unwrap": 1
574
+ },
575
+ "dt": {
576
+ "unwrap": 1
577
+ },
578
+ "nextid": {
579
+ "remove": 1
580
+ },
581
+ "pre": {},
582
+ "center": {
583
+ "rename_tag": "div",
584
+ "set_class": "wysiwyg-text-align-center"
585
+ },
586
+ "audio": {
587
+ "remove": 1
588
+ },
589
+ "datalist": {
590
+ "unwrap": 1
591
+ },
592
+ "samp": {
593
+ "unwrap": 1
594
+ },
595
+ "col": {
596
+ "remove": 1
597
+ },
598
+ "article": {
599
+ "rename_tag": "div"
600
+ },
601
+ "cite": {},
602
+ "link": {
603
+ "remove": 1
604
+ },
605
+ "script": {
606
+ "remove": 1
607
+ },
608
+ "bdo": {
609
+ "unwrap": 1
610
+ },
611
+ "menu": {
612
+ "rename_tag": "ul"
613
+ },
614
+ "colgroup": {
615
+ "remove": 1
616
+ },
617
+ "ruby": {
618
+ "unwrap": 1
619
+ },
620
+ "h2": {
621
+ "add_class": {
622
+ "align": "align_text"
623
+ }
624
+ },
625
+ "ins": {
626
+ "unwrap": 1
627
+ },
628
+ "p": {
629
+ "add_class": {
630
+ "align": "align_text"
631
+ }
632
+ },
633
+ "sub": {
634
+ "unwrap": 1
635
+ },
636
+ "comment": {
637
+ "remove": 1
638
+ },
639
+ "frameset": {
640
+ "remove": 1
641
+ },
642
+ "optgroup": {
643
+ "unwrap": 1
644
+ },
645
+ "header": {
646
+ "rename_tag": "div"
647
+ }
648
+ }
649
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Very simple basic rule set
3
+ *
4
+ * Allows
5
+ * <i>, <em>, <b>, <strong>, <p>, <div>, <a href="http://foo"></a>, <br>, <span>, <ol>, <ul>, <li>
6
+ *
7
+ * For a proper documentation of the format check advanced.js
8
+ */
9
+ var wysihtml5ParserRules = {
10
+ tags: {
11
+ strong: {},
12
+ b: {},
13
+ i: {},
14
+ em: {},
15
+ br: {},
16
+ p: {},
17
+ div: {},
18
+ span: {},
19
+ ul: {},
20
+ ol: {},
21
+ li: {},
22
+ a: {
23
+ set_attributes: {
24
+ target: "_blank",
25
+ rel: "nofollow"
26
+ },
27
+ check_attributes: {
28
+ href: "url" // important to avoid XSS
29
+ }
30
+ }
31
+ }
32
+ };