Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE wraps my text in <p></p>. Can I avoid this?

I am using TinyMCE (http://tinymce.moxiecode.com/) in a .NET page. Whenever I load a text

myTMCE.value=mycontent;

I can see that my text gets wrapped in <p></p>. This is not desirable for me, so I am trying to avoid it. Trying to initialize in

        <script>
            tinyMCE.init({
                force_p_newlines: true
            })

        </script>

did not work. Any idea? Thanks in advance, m.

like image 581
pomarc Avatar asked Apr 29 '09 10:04

pomarc


2 Answers

You need to to do this :

<script>
    tinyMCE.init({
        forced_root_block: false,
        //some other options here
    })
</script>

By default TinyMCE sets as a root block. By setting this property to false you remove any wrapper for the text. The below text is from TinyMCE documentation:

This option enables you to make sure that any non block elements or text nodes are wrapped in block elements. For example something will result in output like:

something

This option is enabled by default as of 3.0a1.

If you set this option to false it will never produce P tags on enter or automatically it will instead produce BR elements and Shift+Enter will produce a P.

Note that not using P elements as root block can severely cripple the functionality of the editor.

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

like image 90
manikata Avatar answered Nov 14 '22 04:11

manikata


See this thread and the answer in TinyMCE forum. force_p_newline is a gecko only option (ie FF).

like image 32
Elazar Leibovich Avatar answered Nov 14 '22 04:11

Elazar Leibovich