2013-04-22 87 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