Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I filter valid styles in a TinyMCE 4.x editor?

In TinyMCE version 3.3.9.4, it was possible to limit the styles to alignment (rejecting coloring options and the like), by using the ´undocumented´ valid_styles option (TinyMCE valid elements: only allow specific CSS rules):

    valid_styles : { '*' : 'text-align' },

Now with the 4.x version, this doesn't seem to work any more. Is there a way to filter valid styles in TinyMCE 4.x, preferably by using built-in editor (client side) methods?

like image 895
gpinkas Avatar asked Oct 16 '25 13:10

gpinkas


1 Answers

valid_styles seems well documented for version 4 :

This option enables you specify the available styles for each element. This means you can force ordering and only specific styles to be valid within style attribute values. Specify the element name, then it's styles or * for all elements.

tinymce.init({
    ...
    valid_styles: {
        "*": "border,font-size",
        "div": "width,height"
    }
});

Here is a tinymce fiddle you can play with.

like image 72
Sébastien Avatar answered Oct 19 '25 13:10

Sébastien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!