Iframe TinyMCE删除有效标记
我使用tinyMCE作为小型网站,人们用它来写简单的文章。通常他们用MS word书写,然后将文本复制到tinyMCE并提交 这就是为什么我只允许几个标记:Iframe TinyMCE删除有效标记,iframe,attributes,tinymce,image,Iframe,Attributes,Tinymce,Image,我使用tinyMCE作为小型网站,人们用它来写简单的文章。通常他们用MS word书写,然后将文本复制到tinyMCE并提交 这就是为什么我只允许几个标记: valid_elements: "a[href|target],strong/b,em/i,div[align],br,p[style|align],ul,li,ol,table,tr,td,iframe[*],img[*]", 但尽管仅通过“插入/编辑图像”插入图像后允许img[*]: <img alt=""/> 出现
valid_elements: "a[href|target],strong/b,em/i,div[align],br,p[style|align],ul,li,ol,table,tr,td,iframe[*],img[*]",
但尽管仅通过“插入/编辑图像”插入图像后允许img[*]:
<img alt=""/>
出现在代码中。iframe也是如此(已完全删除)
我已经尝试过使用img和iframe属性的完整列表以及扩展的\u有效\u元素的所有有效\u元素组合
当我删除valid_elements子句时,一切正常,但随后不允许的单词格式(h1、h2等)会弄乱样式
TinyMCE版本是3.4.2。我正在使用TinyMCE粘贴插件的粘贴预处理设置,并在那里过滤掉不需要的标记。以下是一个例子: 在tinymce init中:
paste_preprocess : function(pl, o) {
//if(console) console.log('Object', o);
//if(console) console.log('Content:', o.content);
// usage param1 = the string to strip out tags from, param2 = tags to keep in the string
o.content = ir.im.strip_tags( o.content,'<p><div><br><br/>' );
},
粘贴预处理:函数(pl,o){
//if(console)console.log('Object',o);
//if(console)console.log('Content:',o.Content);
//用法param1=从中删除标记的字符串,param2=保留在字符串中的标记
o、 content=ir.im.strip_标签(o.content,); }, 删除标签的帮助功能:
strip_tags = function (str, allowed_tags) {
var key = '', allowed = false;
var matches = []; var allowed_array = [];
var allowed_tag = '';
var i = 0;
var k = '';
var html = '';
var replacer = function (search, replace, str) {
return str.split(search).join(replace);
};
// Build allowes tags associative array
if (allowed_tags) {
allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
}
str += '';
// Match tags
matches = str.match(/(<\/?[\S][^>]*>)/gi);
// Go through all HTML tags
for (key in matches) {
if (isNaN(key)) {
// IE7 Hack
continue; }
// Save HTML tag
html = matches[key].toString();
// Is tag not in allowed list? Remove from str!
allowed = false;
// Go through all allowed tags
for (k in allowed_array) { // Init
allowed_tag = allowed_array[k];
i = -1;
if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag) ;}
// Determine
if (i == 0) { allowed = true;
break;
}
}
if (!allowed) {
str = replacer(html, "", str); // Custom replace. No regexing
}
}
return str;
};
strip\u tags=函数(str,允许的\u标记){
var key='',allowed=false;
var匹配=[];允许的var_数组=[];
允许的var_标记=“”;
var i=0;
var k='';
var html='';
var replacer=函数(搜索、替换、str){
返回str.split(搜索)。join(替换);
};
//构建allowes标记关联数组
如果(允许的\u标记){
允许的_数组=允许的_标记匹配(/([a-zA-Z0-9]+)/gi);
}
str+='';
//匹配标签
matches=str.match(/(]*>)/gi);
//检查所有HTML标记
用于(输入匹配项){
如果(isNaN(键)){
//IE7黑客
继续;}
//保存HTML标记
html=匹配[key].toString();
//标签不在允许列表中吗?从str中删除!
允许=错误;
//检查所有允许的标签
对于(k在允许的_数组中){//Init
允许的_标记=允许的_数组[k];
i=-1;
如果(i!=0){i=html.toLowerCase().indexOf(“”);}
如果(i!=0){i=html.toLowerCase().indexOf('我正在使用tinymce粘贴插件的粘贴预处理设置,并在那里过滤掉不需要的标记。下面是一个示例:
在tinymce init中:
paste_preprocess : function(pl, o) {
//if(console) console.log('Object', o);
//if(console) console.log('Content:', o.content);
// usage param1 = the string to strip out tags from, param2 = tags to keep in the string
o.content = ir.im.strip_tags( o.content,'<p><div><br><br/>' );
},
粘贴预处理:函数(pl,o){
//if(console)console.log('Object',o);
//if(console)console.log('Content:',o.Content);
//用法param1=从中删除标记的字符串,param2=保留在字符串中的标记
o、 content=ir.im.strip_标签(o.content,
);
},
删除标签的帮助功能:
strip_tags = function (str, allowed_tags) {
var key = '', allowed = false;
var matches = []; var allowed_array = [];
var allowed_tag = '';
var i = 0;
var k = '';
var html = '';
var replacer = function (search, replace, str) {
return str.split(search).join(replace);
};
// Build allowes tags associative array
if (allowed_tags) {
allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
}
str += '';
// Match tags
matches = str.match(/(<\/?[\S][^>]*>)/gi);
// Go through all HTML tags
for (key in matches) {
if (isNaN(key)) {
// IE7 Hack
continue; }
// Save HTML tag
html = matches[key].toString();
// Is tag not in allowed list? Remove from str!
allowed = false;
// Go through all allowed tags
for (k in allowed_array) { // Init
allowed_tag = allowed_array[k];
i = -1;
if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag) ;}
// Determine
if (i == 0) { allowed = true;
break;
}
}
if (!allowed) {
str = replacer(html, "", str); // Custom replace. No regexing
}
}
return str;
};
strip\u tags=函数(str,允许的\u标记){
var key='',allowed=false;
var匹配=[];允许的var_数组=[];
允许的var_标记=“”;
var i=0;
var k='';
var html='';
var replacer=函数(搜索、替换、str){
返回str.split(搜索)。join(替换);
};
//构建allowes标记关联数组
如果(允许的\u标记){
允许的_数组=允许的_标记匹配(/([a-zA-Z0-9]+)/gi);
}
str+='';
//匹配标签
matches=str.match(/(]*>)/gi);
//检查所有HTML标记
用于(输入匹配项){
如果(isNaN(键)){
//IE7黑客
继续;}
//保存HTML标记
html=匹配[key].toString();
//标签不在允许列表中吗?从str中删除!
允许=错误;
//检查所有允许的标签
对于(k在允许的_数组中){//Init
允许的_标记=允许的_数组[k];
i=-1;
如果(i!=0){i=html.toLowerCase().indexOf(“”);}
如果(i!=0){i=html.toLowerCase().indexOf('