views:

448

answers:

4

I have TinyMCE installed on the back end of a site. Some of the html it's accessing isn't totally valid, which I realize is the problem in itself. However, TinyMCE is messing things up by making things valid. I have an <img> with no parents (no <p>, no <div>, etc), and TinyMCE is wrapping the <img> in <p></p>. I'm trying to find a setting that will stop that from happening.

Essentially, I want TinyMCE to allow <img> to be it's own element, rather than a child element, if that makes sense. My current settings are:

tinyMCE.init({
   theme : "advanced",
   mode : "textareas",
   relative_urls : false
});
+1  A: 

I'm not an expert in tinyMCE but I'm pretty sure those automatic 'clever' source formatting or modification can be configured. Not sure if you have looked into that.

Example of usage of the force_p_newlines option:

tinyMCE.init({
    ...
    force_p_newlines : true
});

Take a look at the reference here:
http://wiki.moxiecode.com/index.php/TinyMCE%3AConfiguration

o.k.w
I've been playing with the configuration options, I just can't seem to find the one that stops the clever formatting. I'll keep guessing and checking. I just tried setting force_p_newlines to false, and foce_br_newlines to true. No change. Thanks for the thought though. :)
hookedonwinter
A: 

I did a little more searching, and found an answer. First, I actually fixed the inherent problem by wrapping the <img> in a <div style="display:inline;">. However, the configuration solution can be found here:

http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_child_elements

I attempted to just force the <body> tag to allow parentless images:

valid_child_elements: "body[img]"

but that denied all other tags from working. So I added some variables, like that link shows, and then I realized the proper solution. But, should anyone need to hack together a solution for an element, that page should solve the problem.

hookedonwinter
Great for you! You can accept your own answer :-)
o.k.w
"You can acce[t your own answer in 2 days." -- StackOverflow noob I am :)
hookedonwinter
A: 

I had the same problem before I found this: http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/forced_root_block

A bit late, but maybe it will help someone in the future

gofry
A: 

@hookedonwinter great! now what was the actual string you used to stop IMG being wrapped in p tags!!??

danwellman
Check the file in the link in my answer. Here is my js:<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({theme : "advanced",mode : "textareas",relative_urls : false,force_br_newlines : true,forced_root_block : ''});</script>
hookedonwinter