TinyMCE is making my code valid, and I want it to stop! (<img> tag wrapped in <p>)
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 (n开发者_开发百科o <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
});
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
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:Configuration
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.
精彩评论