Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE stripping style tags

Is there a way to get TinyMCE V4 to not remove <style> tags.

  tinymce.init({
    selector: 'textarea.tinymce',
    theme: 'modern',
    plugins: [
      'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
      'searchreplace wordcount visualblocks visualchars code insertdatetime media nonbreaking',
      'save table contextmenu directionality emoticons template paste textcolor'
    ],
    valid_elements: '+*[*]',
    width: '100%',
    inline_styles: true,
    keep_styles: true,
    extended_valid_elements: '+*[*]',
    custom_elements: '*',
    invalid_elements: '',
    verify_html: false
  });

I want to be able to add any HTML I want whether valid or not. I don’t care if it is a fork or a workaround.

like image 358
Kirk Strobeck Avatar asked Jul 02 '16 23:07

Kirk Strobeck


2 Answers

You can use TinyMCE's valid_children option for that:

valid_children : '+body[style]',

Check this fiddle for a complete example.

The valid_children enables you to control what child elements can exists within specified parent elements.

like image 178
Dekel Avatar answered Nov 18 '22 02:11

Dekel


Define style and link as a custom tag to keep them:

tinymce.init({
...
    extended_valid_elements:"style,link[href|rel]",
    custom_elements:"style,link,~link"
...
});
like image 29
Wayne Avatar answered Nov 18 '22 02:11

Wayne