Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to allow style tags in TinyMCE?

Vote:
 

I thought this was an easy one, just use extended_valid_elements, right?

So, i tried this:

        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            context.Services.Configure<TinyMceConfiguration>(config =>
            {
                // Add content CSS to the default settings.
                config.Default()
                    .AddSetting("extended_valid_elements", "script[*],style[*],iframe[*]")
                    .AddPlugin("code")
                    .Toolbar("code");
            });
        }

It does not work. I've tested in EPiServer.CMS.TinyMce 2.10.1 and EPiServer.CMS.TinyMce 2.13.0.

Do I really have to use an TinyMCEPluginNonVisual like descripbed in this 2013-post?

https://www.cjsharp.com/blog/2013/04/15/how-to-add-valid-elements-like-iframes-to-tinymce-in-episerver-7/

#228429
Sep 25, 2020 19:26
Vote:
 

Hi Tom,

Try this-

context.Services.Configure<TinyMceConfiguration>(config =>
            {
                config.Default()
                    
                    .AddSetting("valid_children", "+body[style]").AddSetting("extended_valid_elements", "script[language|type|src]");
            });
#228509
Sep 28, 2020 10:50
Vote:
 

Thanks, Ravindra! It seem to work, but I don't understand why.

This part is allowing script-tags, so it can't be that.

.AddSetting("extended_valid_elements", "script[language|type|src]");

I don't understand how adding style as a valid child of body works, I don't have body-tags inside my TinyMCE-editor. When the page is renderes style ends up as a child of body, but how can TinyMCE know that?

.AddSetting("valid_children", "+body[style]")

Can you provide some insight on why this works? I'm utterly confused :-)

#228510
Edited, Sep 28, 2020 11:04
Vote:
 

Hi Tom,

I think it just checks for valid_children. Once it's valid then it applies to all the tags until you remove this from any specific tag.

I am also not sure how it is working in the background.

#228511
Sep 28, 2020 11:25
Vote:
 

Adding this was enough:

.AddSetting("valid_children", "+body[style]")

Thanks! :-)

#228514
Sep 28, 2020 17:37
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.