wysihtml-rails 0.5.0.beta2

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