diff --git a/wagtailtinymce/wagtail_hooks.py b/wagtailtinymce/wagtail_hooks.py index 342effb1..59d915e1 100644 --- a/wagtailtinymce/wagtail_hooks.py +++ b/wagtailtinymce/wagtail_hooks.py @@ -36,6 +36,7 @@ from wagtail.wagtailadmin.templatetags.wagtailadmin_tags import hook_output from wagtail.wagtailcore import hooks +from wagtail.wagtailcore.whitelist import attribute_rule, allow_without_attributes def to_js_primitive(string): @@ -132,3 +133,50 @@ def docs_richtexteditor_js(): to_js_primitive(static('wagtailtinymce/js/tinymce-plugins/wagtaildoclink.js')), to_js_primitive(translation.to_locale(translation.get_language())), ) + + +@hooks.register('construct_whitelister_element_rules') +def whitelister_element_rules(): + common = { + 'style': True, + 'width': True, + 'margin-left': True, + 'margin-right': True, + 'height': True, + 'border-color': True, + 'text-align': True, + 'background-color': True, + 'vertical-align': True, + 'font-family': True, + 'valign': True, + } + + table_rule = attribute_rule(dict(common, **{ + 'border': True, + 'cellpadding': True, + 'cellspacing': True, + })) + row_rule = attribute_rule(common) + cell_rule = attribute_rule(dict(common, **{ + 'colspan': True, + 'scope': True, + 'rowspan': True, + })) + + return { + 'blockquote': allow_without_attributes, + 'pre': allow_without_attributes, + 'span': allow_without_attributes, + 'code': allow_without_attributes, + + 'table': table_rule, + 'thead': allow_without_attributes, + 'tfoot': allow_without_attributes, + 'tbody': allow_without_attributes, + 'colgroup': allow_without_attributes, + 'col': allow_without_attributes, + 'caption': allow_without_attributes, + 'tr': row_rule, + 'th': cell_rule, + 'td': cell_rule, + }