2010-08-09 115 views
4

我們運行一些大型目錄,其中用戶經常從Word文檔等複製/粘貼內容到我們的TinyMCE html編輯器中。javascript html編輯器複製/粘貼問題

的問題,這通常例如下面的文字被隱藏在那裏這說明了我們的網頁:

<!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; mso-layout-grid-align:none; punctuation-wrap:simple; text-autospace:none; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} p {mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> 

有TinyMCE的插件或其他一些跨瀏覽器的HTML編輯器,自動剝了這一點?

或者另一種解決方案是使用一些php regex命令或者可以去掉這些註釋聲明的東西。

+0

祝您好運。我看了看,看了看,還沒有發現任何東西,但我正在看這篇文章,像一個鷹,希望有人比手動使用Dreamweaver清理Word的混亂有更好的解決方案。 – Brad 2010-08-09 16:11:55

+0

嘗試ckeditor在http://ckeditor.com/ – 2010-08-09 16:23:47

+0

可能重複的[tinymce和導入/從微軟word複製粘貼](http://stackoverflow.com/questions/1255738/tinymce-and-importing-copy-paste- from-microsoft-word) – 2010-08-09 16:42:55

回答

3

我一直在試圖優化那一年多年。

我最好的解決方案,到目前爲止是這樣的:

  • 不使用根塊,佈局將實行根佈局
  • 不希望用戶瞭解<p>之間的差異, <br />和治療爲此作爲一切簡單的休息,因爲它是減少混亂和更多的MS-字狀
  • 只允許預期元素

竟被這d是初始代碼

remove_linebreaks : false, 
force_br_newlines : true, <?php /* maybe we can behave more like gmail */ ?> 
force_p_newlines : false, <?php /* and preserve all message line breaks */ ?> 
convert_newlines_to_brs : false, <?php /* even so i would not count with it */ ?> 
forced_root_block : false 

<?php /* explicitly define what will be allowed */ ?> 
valid_elements: "h1,h2,h3,br,b,a,i,u,strong/b,em/i,u/span,strike/span,span,span[style],"+ 
       "sub,sup,a[href|name|anchor|target|title],ul,ol,li,p,object[classid|width|height|codebase|*],"+ 
       "param[name|value|_value],embed[type|width|height|src|*],"+ 
       "img[style|longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align]", 

然後,我有以下的後處理功能,以消除所有<p>和轉換所有</p><br /><br />這一直是最穩定的複製粘貼解決方案,我已經能夠dev的。

這是後處理功能

setup : function(ed) { 
    ed.onPostProcess.add(function(ed, o) { 
     // Remove all paragraphs and replace with BR 
     o.content = o.content.replace(/<p [^>]+>|<p>/g, ''); 
     o.content = o.content.replace(/<\/p>/g, '<br />'); 
    }); 
}, 

執行通知,這一切都只是Java腳本過濾,用戶將能夠通過所有非需要的代碼到服務器瞬間。儘管此設置可能用於最終管理員設置,但也可以在服務器端使用strip_tags,因爲某處某個人可能會繞過它。

希望它能幫助!

+0

賓果!非常感謝! – Joe 2010-08-10 08:44:28

1

PHP正則表達式命令是我個人使用的。

$str = preg_replace('/<!--.*?--\>/','',$str); 
+0

完美,會給這個鏡頭 – Joe 2010-08-10 08:34:00