out*_*d3r 27 html javascript css tinymce
让我们把<script>在Web编辑器中允许内容的问题放在一边; 我完全了解他们.
我想要的是允许<style>和<script>文本内容中的元素,问题在于,每当我这样做时,TinyMCE将它们更改为:
<style><!-- th{width:80px} --></style>
Run Code Online (Sandbox Code Playgroud)
并且脚本内容更改为:
<script>// <![CDATA[
$.address.unbind();
// ]]></script>
Run Code Online (Sandbox Code Playgroud)
在我的TinyMCE init配置中,我有:
valid_elements : "*[*]",
extended_valid_elements : "*[*],script[charset|defer|language|src|type],style",
custom_elements: "*[*],script[charset|defer|language|src|type],style",
valid_children : "+body[style],+body[script]",
verify_html : false,
media_strict: false
Run Code Online (Sandbox Code Playgroud)
但我似乎无法找到一个方法来防止TinyMCE的从禁用的<style>和<script>元素.
小智 7
如果可以避免,我建议避免对第三方库进行任何直接定制.相反,我在初始化期间向编辑器序列化程序添加了一个自定义节点过滤器,方法是将以下内容添加到传递给tinymce构造调用的config对象中:
init_instance_callback : function(editor) {
// jw: this code is heavily borrowed from tinymce.jquery.js:12231 but modified so that it will
// just remove the escaping and not add it back.
editor.serializer.addNodeFilter('script,style', function(nodes, name) {
var i = nodes.length, node, value, type;
function trim(value) {
/*jshint maxlen:255 */
/*eslint max-len:0 */
return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
.replace(/^[\r\n]*|[\r\n]*$/g, '')
.replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
.replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
}
while (i--) {
node = nodes[i];
value = node.firstChild ? node.firstChild.value : '';
if (value.length > 0) {
node.firstChild.value = trim(value);
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
希望这将有助于其他人陷入同一条船.
您可以尝试更改tinymce.min.js
,f.addNodeFilter("script,style",function(e,t){function n(e){return e.replace(/(<!--\[CDATA\[|\]\]-->)/g,"\n").replace(/^[\r\n]*|[\r\n]*$/g,"").replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi,"").replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g,"")}for(var r=e.length,i,o,a;r--;)i=e[r],o=i.firstChild?i.firstChild.value:"","script"===t?(a=i.attr("type"),a&&i.attr("type","mce-no/type"==a?null:a.replace(/^mce\-/,"")),o.length>0&&(i.firstChild.value="// <![CDATA[\n"+n(o)+"\n// ]]>")):o.length>0&&(i.firstChild.value="<!--\n"+n(o)+"\n-->")}),f.addNodeFilter("#comment",function(e){for(var t=e.length,n;t--;)n=e[t],0===n.value.indexOf("[CDATA[")?(n.name="#cdata",n.type=4,n.value=n.value.replace(/^\[CDATA\[|\]\]$/g,"")):0===n.value.indexOf("mce:protected ")&&(n.name="#text",n.type=3,n.raw=!0,n.value=unescape(n.value).substr(14))})
Run Code Online (Sandbox Code Playgroud)
请从文件中找到并删除上面的代码行。
| 归档时间: |
|
| 查看次数: |
6433 次 |
| 最近记录: |