<pre><code> get removed, when switching from HTML to Visual Editor tinymce editor

时间:2019-01-15 18:04:01

标签: tinymce tinymce-4 tinymce-plugins

New line(\n) placed in a <pre><code></code></pre> block are stripped and line breaks are removed leaving a single continuous line of text. This occurs when switching from html to visual editors. Is there a setting in TinyMCE or hack to avoid this?

A visual example of my problem, I do use "code sample" plugin in TinyMCE editor, when I create code block using the text, the code looks like this

<pre class="language-markup"><code>&lt;php
echo "1st line";
echo "2nd line";</code></pre>

And output becomes this enter image description here

When I save the above text it saves as it is in the database (With the line break - same as above code). enter image description here

When I try to edit the text again, new lines are getting removed by the TinyMCE editor so it does appear in a single line like,

    <pre class="language-markup"><code>&lt;php echo "1st line"; echo "2nd line";</code></pre>

enter image description here

So how can I keep the line break for the code block? Bellow is the code how I init the TinyMCE

    tinymce.init({
        remove_linebreaks : false,
        convert_newlines_to_br: true,
        force_br_newlines : true,
    });

please let me know if anything more required...

0 个答案:

没有答案