简体   繁体   中英

Use <style> tag in TinyMCE

I'm trying to add css in a <style> tag in a TinyMCE editor but when I validate the HTML changes, TinyMCE automatically put my css between comments.

Exemple :

If I type

<style>
h3{
   font-size:50px;
}
</style>
<h3>Hello</h3>

TinyMCE transforms that in :

<style>
h3{<!--
   font-size:50px;-->
}
</style>
<h3>Hello</h3>

In the setup I set :

extended_valid_elements: "pre[*],script[*],style[*]",
valid_children: \'+body[style|script],pre[script|div|p|br|span|img|style|h1|h2|h3|h4|h5],*[*]\',
valid_elements : \'*[*]\',

Am I doing something wrong ?

The last poster on this thread ( http://www.tinymce.com/forum/viewtopic.php?id=25443 ) writes:

TinyMCE produces XHTML and we wrap the style contents in a comment to keep any XML parser from failing to parse the contents all browsers support the comment syntax. --Spocke

so the answer is that no, this cannot be changed , because tiny mce not only is sworn to generate valid HTML , but must also generate valid (ughh) XHTML . Since they say all browsers support the comment syntax then it shouldn't really be a problem for you.

If you put tinyMCE in fullpage mode, you can put styles in the <head> . It will not put the comment node there.

<script type="text/javascript">
tinyMCE.init({
        plugins : "fullpage",
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM