Search code examples
tinymcetinymce-5

TinyMce disable all possibilities to insert paragraphs


I need TinyMce to write Markdown with formatting options. Here I do not need paragraphs, simple <br> elements which can be reliably replaced to \n would be best.

To illustrate the problem, the following output was created after inserting the third line as a paragraph:

<p>## Heading<br />
Some Text</p>
<p>Some More Text</p>

I cannot think of an easy solution to find and replace incorrect paragraphs like the ones around the first block. Thus I want to turn off paragraphs completely.

I already found the configuration forced_root_block : '' to disable automatic creation of paragraphs for every line break. Here the solution is shown how to disable Shift+Enter. The last remaining puzzle piece is the styleselect-toolbar, which has a possibility to add paragraphs. I only found a solution how to add options to that toolbar, but not how to hide or remove.

Can someone help me how to hide the paragraph-style from the styleselect toolbar? Or maybe point out that I am missing an elegant solution which completely disables paragraphs in one step?


Solution

  • With Try-and-Error I changed the following part in the current themes theme.js, which hides the "Paragraph" button in the styleselect-toolbar:

      var defaultStyleFormats = [
        ...
      {
        title: 'Blocks',
        items: [
          {// removed this block
            title: 'Paragraph',
            format: 'p'
          },
          {
            title: 'Blockquote',
            format: 'blockquote'
          },
        ...
    

    Removing part of the JS file was possible because we do not import it from npm but rather copied the code manually in our repository. So this solution might not apply to everyone.