pomarc
pomarc

Reputation: 2224

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.

Upvotes: 7

Views: 7786

Answers (4)

manikata
manikata

Reputation: 91

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

Upvotes: 9

soulmerge
soulmerge

Reputation: 75714

TinyMCE adds a whole load of tags to the text - its design goal is to create valid html from arbitrary input (including html input). If you want control over the generated html code, you're better off using another editor.

Upvotes: 0

Elazar Leibovich
Elazar Leibovich

Reputation: 33593

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

Upvotes: 1

White Elephant
White Elephant

Reputation: 1381

You could strip <p> tags after the fact using .NET, or alternatively, just use a plain <textarea> field for data entry if that suits what you're trying to do.

Upvotes: 0

Related Questions