File tree 2 files changed +52
-0
lines changed
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 47
47
" rt" ,
48
48
" rp"
49
49
],
50
+ "allowedClasses" : {
51
+ "th" : [
52
+ " text-center" ,
53
+ " text-left" ,
54
+ " text-right"
55
+ ],
56
+ "td" : [
57
+ " text-center" ,
58
+ " text-left" ,
59
+ " text-right"
60
+ ]
61
+ },
50
62
"allowedAttributes" : {
63
+ "th" : [
64
+ " class"
65
+ ],
66
+ "td" : [
67
+ " class"
68
+ ],
51
69
"a" : [
52
70
" href"
53
71
],
Original file line number Diff line number Diff line change @@ -27,6 +27,40 @@ htmlWhitelistPost.allowedTags.forEach(function (aTag) {
27
27
} ) ;
28
28
delete htmlWhitelistPost . allowedAttributes . all ;
29
29
30
+ // Transform exact Github Flavored Markdown generated style tags to bootstrap custom classes
31
+ // to allow the sanitizer to whitelist on th and td tags for table alignment
32
+ function gfmStyleToBootstrapClass ( aTagName , aAttribs ) {
33
+ if ( aAttribs . style ) {
34
+ switch ( aAttribs . style ) {
35
+ case 'text-align:center' :
36
+ return {
37
+ tagName : aTagName ,
38
+ attribs : { class : 'text-center' }
39
+ }
40
+ case 'text-align:left' :
41
+ return {
42
+ tagName : aTagName ,
43
+ attribs : { class : 'text-left' }
44
+ }
45
+ case 'text-align:right' :
46
+ return {
47
+ tagName : aTagName ,
48
+ attribs : { class : 'text-right' }
49
+ }
50
+ }
51
+ }
52
+
53
+ return {
54
+ tagName : aTagName ,
55
+ attribs : aAttribs
56
+ }
57
+ }
58
+
59
+ htmlWhitelistPost . transformTags = {
60
+ 'th' : gfmStyleToBootstrapClass ,
61
+ 'td' : gfmStyleToBootstrapClass
62
+ } ;
63
+
30
64
function sanitize ( aHtml ) {
31
65
return sanitizeHtml ( aHtml , htmlWhitelistPost ) ;
32
66
}
You can’t perform that action at this time.
0 commit comments