CSS TinyMCE 正在删除 <style> 标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3037501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:13:08  来源:igfitidea点击:

TinyMCE is removing <style> tags

csstinymce

提问by jyoti

I'm facing a problem with TinyMCE. When I enter a style tag in the HTML editor of TinyMCE, it removes the tags when I click update.

我遇到了 TinyMCE 的问题。当我在 TinyMCE 的 HTML 编辑器中输入样式标签时,它会在我单击更新时删除标签。

<style type="text/css"> 
     .newclasss { color:#c9c9c9; } 
</style>

My valid elements are follows:

我的有效元素如下:

<script type="text/javascript">

var valid_elms = "hr[class|width|size|noshade]";
valid_elms    += "span[class|align|style],";
valid_elms    += "font[face|size|color|style],";
valid_elms    += "img[href|src|name|title|onclick|align|alt|title|";
valid_elms    += "width|height|vspace|hspace],";
valid_elms    += "iframe[id|class|width|size|noshade|src|height|";
valid_elms    += "frameborder|border|marginwidth|marginheight|";
valid_elms    += "target|scrolling|allowtransparency],style";

extended_valid_elements: valid_elms
</script>

Can anyone help please??

有人可以帮忙吗??

回答by Yaz

Since style tags are not valid XHTML, TinyMCE disabled the ability to add them outside of the tags.

由于样式标签不是有效的 XHTML,TinyMCE 禁用了将它们添加到标签之外的功能。

You have to add style tags to the valid children configuration

您必须将样式标签添加到有效的子配置中

valid_children : "+body[style]"

Edit: This solution applies to version 3.4.2

编辑:此解决方案适用于 3.4.2 版

Source

来源

回答by John

"hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],img[href|src|name|title|onclick|align|alt|title|width|height|vspace|hspace],iframe[id|class|width|size|noshade|src|height|frameborder|border|marginwidth|marginheight|target|scrolling|allowtransparency],style[type]"

Let me know how that works for you

让我知道这对你有什么作用

回答by Erik van Velzen

If you put tinyMCE in fullpage mode, you can put styles in the <head>

如果您将 tinyMCE 置于整页模式,则可以将样式放入 <head>

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

回答by Matthew Lock

It's a bit hacky but I'm using TinyMCE 4 and was in a pinch, so I added a <script>tag in the TinyMCE editor's Source Codeview and used jQuery to change the styles.

这有点老套,但我使用的是 TinyMCE 4 并且处于紧要关头,所以我<script>在 TinyMCE 编辑器的源代码视图中添加了一个标签,并使用jQuery 更改样式

<script>$("#signup").css("font-weight", "bold");</script>

This assumes that TinyMCE has been setup not to disallow script tags, and your page already has jQuery included in it like mine did, if not you could use standard javascript to change styles.

这假设 TinyMCE 已设置为不禁止脚本标记,并且您的页面已经像我一样包含 jQuery,如果没有,您可以使用标准javascript 来更改样式

回答by Walty Yeung

For me, I need to do the following in TinyMCE 4.5.7:

对我来说,我需要在以下内容中执行以下操作TinyMCE 4.5.7

tinyMCE.schema.addValidChildren("body[style]")