Allow only specific formats in tinymce 4 Modern theme?

Is there a β€œmodern theme” (in other words, tinymce 4) equivalent to the theme_advanced_blockformats option?

theme_advanced_blockformats allows you to limit the set of available formats by adding the following to tinymce.init() :

 tinyMCE.init({ ... theme_advanced_blockformats : "p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp" }); 

( TinyMCE Advanced Block Formats )

I know that you can explicitly indicate which formats are available by passing the tinymce.init() option, for example:

 tinyMCE.init({ ... formats : bold : {inline : 'span', 'classes' : 'bold'}, italic : {inline : 'span', 'classes' : 'italic'}, underline : {inline : 'span', 'classes' : 'underline', exact : true}, } }); 

( TinyMCE formats )

Unfortunately, this requires a lot of details about how each format that I don't have is implemented.

Any words of advice?

+4
source share
4 answers

This is the latest version of TinyMCE (4.1.3). Although the "block_formats" setting documents this functionality, I could only get it to work using the following:

  tinymce.init({ selector: "textarea", style_formats: [ {title: 'Paragraph', block: 'p'}, {title: 'Heading 2', block: 'h2'}, {title: 'Heading 3', block: 'h3'}, {title: 'Heading 4', block: 'h4'}, ], }); 

This is a simple example of the documented syntax of custom Tinymce formats .

+5
source

The documentation is a bit spotty right now, but you can control what is a valid block and also define default attributes for blocks using valid elements . Declaring allowed blocks and default styles now depends on the TinyMCE core, not the theme. valid_elements declares allowed blocks and extended_valid_elements declares default attributes for allowed blocks.

 tinymce.init({ selector: "textarea", valid_elements : "a[href|target=_blank],strong/b,div[align],br", extended_valid_elements: "img[class=myclass|!src|border:0|alt|title|width|height]", invalid_elements: "strong,b,em,i" }); 
+1
source

I think this is what you need:

http://www.tinymce.com/wiki.php/Configuration:block_formats

how

block_formats: "Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4"

+1
source

For Tinymce 4x, try the following:

 tinymce.init({ selector: "textarea", block_formats: 'Paragraph=p;Heading 1=h1;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6;Preformatted=pre', }); 

https://www.tiny.cloud/docs-4x/configure/content-formatting/#block_formats

Ben.hamelin's answer did not work for me in v4.8.1.

0
source

All Articles