2013-04-22 89 views
3

我想知道,我找了几个小时后找到解决这个问题的方法。如何使用TinyMCE粘贴插件允许HTML标签?

我想在我的全能TinyMCE的编辑两种模式:

  1. 允许复制/粘贴HTML文本或Word/OpenOffice的文字与大多数样式和格式属性
  2. 粘贴插件默认启用,并删除大部分的HTML,,但允许简单的格式

我能够复制/粘贴大多数样式的HTML文本或Word/OpenOffice文本。 默认情况下也启用粘贴插件按钮。

但是我不知道如何在插件配置糊允许一些HTML标签,特别列表(OL,UL,LI),换行符(BR)和简单的格式(B,I,U),如果粘贴插件按钮被点击。

我试着修改paste_postprocesspaste_preprocess函数,但是没有找到解决办法。还配置valid_elements不会使我成功。

我的设置(重要部件):

plugins : "paste,tabfocus,table,safari", 
paste_auto_cleanup_on_paste : true, 
paste_create_paragraphs: false, 
paste_create_linebreaks : false, 
paste_postprocess : function(pl, o) { }, 
paste_preprocess : function(pl, o) { }, 
paste_remove_spans:true, 
paste_remove_styles:true, 
paste_remove_styles_if_webkit:true, 
paste_retain_style_properties:"none", 
paste_strip_class_attributes:"all", 
paste_text_sticky:true, 
convert_urls : false, 
entity_encoding : "raw", 
valid_elements : "em/i,strong/b,ol,ul,li,br", 
force_br_newlines : true, 
force_p_newlines : false, 
forced_root_block : false, 
invalid_elements : "font", 
setup : function(ed) { 
    ed.onInit.add(function(ed) { 
    ed.pasteAsPlainText = true; // select "paste" on startup 
    }); 
}, 
verify_html : false 
+0

我的TinyMCE版本:3.4.9。所有在Firefox 20上使用Firefox 20的测试。 – malisokan 2013-04-22 14:21:46

回答

2

使用粘贴配置设置paste_preprocess您可以过滤传入的内容,并只保留你想保留的标签。 仔细看看这里:TinyMCE Paste As Plain Text

+0

好吧,我会再次尝试编辑paste_preprocess。但是,我必须将paste_auto_cleanup_on_paste设置为false吗? – malisokan 2013-04-22 14:23:13

+0

afaik,这没关系(我没有改变默认的是真的) – Thariama 2013-04-23 07:39:31