A new feature for SilverStripe should be ...

TinyMCE: Ability to extend "valid_elements" intuitively

Hi, I was noticing that for me to add the ability to have `aria-*` prefixed elements in TinyMCE, I'd need to override the `valid_elements` option on a configuration instance from `HtmlEditorConfig::get('cms')`. Even then, I'd have to do it late in the game (e.g. in an extension and not in `mysite/_config.php`) but I digress.

Basically I see that `HtmlEditorSanitiser` does all the heavy lifting of parsing these complicated rules. And, instead of having to override this entire `valid_elements` string (which is quite large and cumbersome) I feel like this option should first either be composed of an option with a more complex data structure which can be augmented prior to being compiled (like some sort of multi-dimensional array) or maybe expose some of the parsing niftiness contained within the magical `->addValidElements()` method. So, instead of doing this:

. "|class|aria*],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],"
. "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align|data*],"
. "-sub[class],-sup[class],-blockquote[dir|class],-cite[dir|class|id|title],"
. "-table[cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],"
. "-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],"
. "tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],"
. "#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],"
. "-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],"
. "-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align],address[class|align],"
. "-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],"
. "-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],"
. "dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class]"

.... which is fairly intimidating, I could just call some method like:

// Augment.

// Replace/override.

And the framework would parse the rule passed to `->addValidElementsRule(...)` and merge it into the existing rules for me.

8 votes
Sign in
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Patrick Nelson shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
Sign in with: facebook google
Signed in as (Sign out)

Feedback and Knowledge Base