如何在 redactor v9.2.1 中允许 <style> 标签?
How do you allow <style> tags in redactor v9.2.1?
我正在使用 Redactor v9.2.1。我试图让我的客户在他们的 CMS 中使用样式标签,但编辑器将它们从内容中删除。
当我添加以下内容时:
<style type="text/css">
.red{color:red;}
</style>
redactor 将其剥离为:
<p>
.red{color:red;}
</p>
我已确保 deniedTags 不包括 'style' 在我的设置对象中,并且我没有使用 allowedTags 属性,因为它与 deniedTags 冲突。
这是我传递给编辑器 init 的设置对象:
var settings = {
deniedTags:[
'html', 'head','link', 'body', 'meta', 'applet'
],
observeLinks: true,
iframe: true,
convertVideoLinks: true
};
感谢任何帮助。
http://imperavi.com/redactor/docs/settings/clean/#setting-deniedTags
Top-level HTML tags ('html', 'head', 'link', 'body', 'meta', 'style',
'script', 'applet') will always be removed regardless of this setting,
unless wrapped in 'pre' tag (formatting option 'Code')
编辑
所以你不能在编辑器中添加 style
标签,正如我在文档中看到的那样。看起来你有这些选择:
在编辑器外设置单个标签的样式:添加父选择器 .redactor-editor
,然后添加标签名称。见 http://imperavi.com/redactor/examples/typography/
添加几个 formattingAdd
选项让用户从 formatting
下拉列表中选择自定义样式:
$('#redactor').redactor({
formattingAdd: [
{
tag: 'p',
title: 'Red Block',
class: 'red-style'
}
]
});
/**
* The above would create a new formatting entry,
* which you define with 2 css selectors:
* one for the class of the entry, another for the dropdown entry
*
* .red-style, .redactor-dropdown .redactor-formatting-red-style {
* color: red;
* }
*/
注意下拉列表的 css 选择器规则,即 .redactor-dropdown .redactor-formatting-YOUR_CSS_CLASSNAME
。这也很重要:
formattingAdd can only be applied to p, pre, blockquote and header
tags.
所以你不能将它应用到 <div>
。如果需要块元素,使用<p>
。此外,如果您需要内联,您 可以 使用 <span>
... 它有效,请参阅 fiddle:http://jsfiddle.net/a4df10vj/1/
我正在使用 Redactor v9.2.1。我试图让我的客户在他们的 CMS 中使用样式标签,但编辑器将它们从内容中删除。
当我添加以下内容时:
<style type="text/css">
.red{color:red;}
</style>
redactor 将其剥离为:
<p>
.red{color:red;}
</p>
我已确保 deniedTags 不包括 'style' 在我的设置对象中,并且我没有使用 allowedTags 属性,因为它与 deniedTags 冲突。
这是我传递给编辑器 init 的设置对象:
var settings = {
deniedTags:[
'html', 'head','link', 'body', 'meta', 'applet'
],
observeLinks: true,
iframe: true,
convertVideoLinks: true
};
感谢任何帮助。
http://imperavi.com/redactor/docs/settings/clean/#setting-deniedTags
Top-level HTML tags ('html', 'head', 'link', 'body', 'meta', 'style', 'script', 'applet') will always be removed regardless of this setting, unless wrapped in 'pre' tag (formatting option 'Code')
编辑
所以你不能在编辑器中添加 style
标签,正如我在文档中看到的那样。看起来你有这些选择:
在编辑器外设置单个标签的样式:添加父选择器
.redactor-editor
,然后添加标签名称。见 http://imperavi.com/redactor/examples/typography/添加几个
formattingAdd
选项让用户从formatting
下拉列表中选择自定义样式:$('#redactor').redactor({ formattingAdd: [ { tag: 'p', title: 'Red Block', class: 'red-style' } ] }); /** * The above would create a new formatting entry, * which you define with 2 css selectors: * one for the class of the entry, another for the dropdown entry * * .red-style, .redactor-dropdown .redactor-formatting-red-style { * color: red; * } */
注意下拉列表的 css 选择器规则,即 .redactor-dropdown .redactor-formatting-YOUR_CSS_CLASSNAME
。这也很重要:
formattingAdd can only be applied to p, pre, blockquote and header tags.
所以你不能将它应用到 <div>
。如果需要块元素,使用<p>
。此外,如果您需要内联,您 可以 使用 <span>
... 它有效,请参阅 fiddle:http://jsfiddle.net/a4df10vj/1/