2015-01-06 99 views
1

我嘗試重寫peranhacms中的默認tinymce,就像這裏建議的那樣Configure/override Piranha CMS html editor so as not to add &nbsp's to html 我花了大約一個小時來嘗試解決這個問題。這個問題有很多資源,但無法實現。Tinymce添加

這裏是我的tinymce.init的樣子。

<script type="text/javascript" src="~/res.ashx/areas/manager/content/js/ext/tiny_mce/tinymce.min.js"></script> 
<script type="text/javascript"> 
    tinymce.init({ 
     mode: 'specific_textareas', 
     editor_selector: "editor", 
     apply_source_formatting: false, 
     cleanup_on_startup: false, 
     trim_span_elements: false, 
     cleanup: false, 
     convert_urls: false, 
     force_br_newlines: true, 
     force_p_newlines: false, 
     remove_linebreaks: false, 
     convert_newlines_to_brs: false, 
     forced_root_block: '', 
     inline_styles : true, 
     entity_encoding: 'raw', 
     verify_html: false, 
     //forced_root_block: false, 
     validate_children: false, 
     remove_redundant_brs: false, 
     fix_table_elements: false, 

     entities: '160,nbsp,38,amp,60,lt,62,gt', 

     plugins: [ 
      "autoresize autolink code hr paste piranhaimage link" 
     ], 
     width: "100%", 
     height: "340", 
     autoresize_min_height: 340, 
     @if (File.Exists(Server.MapPath("~/areas/manager/content/css/editor.css"))) { 
     <text>content_css: "@Url.Content("~/areas/manager/content/css/editor.css")",</text> 
     } 
     toolbar: "bold italic underline | bullist numlist hr | formatselect removeformat | cut copy paste | link piranhaimage | code", 
     paste_auto_cleanup_on_paste: false, 
     paste_postprocess: function (pl, o) { 
      // remove extra line breaks 
      o.node.innerHTML = o.node.innerHTML.replace(/&nbsp;/ig, " "); 
      alert("a1"); 
     }, 
     cleanup_callback: 'my_cleanup_callback', 
    }); 
    function my_cleanup_callback(type, value) { 
     alert("a2"); 
     switch (type) { 
      case 'get_from_editor': 
       // Remove &nbsp; characters 
       value = value.replace(/&nbsp;/ig, ' '); 
       alert("a3"); 
       break; 
      case 'insert_to_editor': 
      case 'submit_content': 
      case 'get_from_editor_dom': 
      case 'insert_to_editor_dom': 
      case 'setup_content_dom': 
      case 'submit_content_dom': 
      default: 
       break; 
     } 
     return value; 
    } 
</script> 

這裏是我使用粘貼到tinyice textarea的

<div class="catelog-box"> 
    <img src="images/dance.png" alt="dine"> 
    <div class="cat-detail"> 
    <h2>Dance</h2> 
    <p>Dis purus arcu etiam auctor risus aliquam mid turpis eu vel, nunc rhoncus lacus natoque ridiculus...</p>   
    </div> 
</div> 

HTML的例子,這是它是如何尋找在瀏覽器源: enter image description here

我把警報檢查如果paste_postprocessmy_cleanup_callback實際發射,但它們不是。而且我在html中仍然有這個功能。

我試圖設置cleanup: truepaste_auto_cleanup_on_paste: true,但它是沒有幫助火paste_postprocessmy_cleanup_callback

你將如何解決& NBSP問題?

回答

0

TinyMCE的是選項和設置的怪物,但由於您提供和你使用從TinyMCE is adding &nbsp instead of the space when using the word paste清理方法的鏈接,你已嘗試設置:

paste_auto_cleanup_on_paste: true 

由於這在您引用的示例中設置。除了這個猜測之外,我不知道爲什麼這個事件沒有被解僱。

問候

哈坎

1

下面的代碼清理我一切都在TinyMCE的內容

tinymce.init({ 
    selector: "textarea", 
    invalid_elements :'strong,bold,b,em,br,span,div,p,img,a,table,td,th,tr,header,font,body,h,h1,h2,h3,h4,h5', 
    invalid_styles: 'color font-size text-decoration font-weight', 
    menubar: false, 
    toolbar:false, 
    statusbar:false, 
    forced_root_block : "", 
    cleanup: true, 
    remove_linebreaks: true, 
    convert_newlines_to_brs: false, 
    inline_styles : false, 
    entity_encoding: 'raw', 
    entities: '160,nbsp,38,amp,60,lt,62,gt', 
});} 
5

只是增加entity_encoding: 'raw'解決了這個問題。

1

我知道這是舊的,但將這個CSS屬性添加到您的編輯器元素可以解決問題。這不是一個tinyMCE問題,這是可編輯divs的工作原理。

#editor { 
    white-space: pre-wrap; 
    word-wrap: break-word; 
} 

乾杯