2014-07-06 63 views
0

當我將代碼編輯器中的格式化代碼複製到tinymce PRE標記中時,它將刪除所有縮進(\ t)。我嘗試了所有的粘貼配置參數,但沒有幫助。當粘貼到tinymce時保持縮進

有效代碼:

enter image description here

當貼進TinyMCE的

enter image description here

+0

另一個使用空格而不是製表符壓縮的原因。 – geoffspear

+0

我想我需要用editor.on('BeforeSetContent')來處理粘貼事件以將\ t替換爲多個空格,但是接收的內容是html。 – trinvh

+0

@trinvh你有沒有想過這個? – leen3o

回答

0

有一個名爲paste插件具有鬆動凹痕而粘貼的副作用。這個插件用於從Microsoft Word複製粘貼。如果您不使用此功能,那麼以下更改將適用於您 -

  1. 從應用的插件列表中刪除粘貼插件。
  2. 此行添加到您的初始化配置 - forced_root_block:「前

以下是我的init配置 -

tinyMCE.init({ 
     remove_linebreaks: true, 
     preformatted : true, 
     apply_source_formatting : true, 
     selector:'textarea', 
     forced_root_block : 'pre', 
     mode: "textareas", 
     height: "300", 
     force_br_newlines : true, 
     force_p_newlines : false, 
     theme: 'modern', 
     plugins: ['advlist autolink lists link image charmap print preview hr anchor pagebreak', 
     'searchreplace wordcount visualblocks visualchars code fullscreen', 
     'insertdatetime media nonbreaking save table contextmenu directionality', 
     'emoticons template textcolor colorpicker textpattern imagetools' 
     ], 
     toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image', 
     toolbar2: 'print preview media | forecolor backcolor emoticons', 
     image_advtab: true, 
     templates: [ 
     { title: 'Test template 1', content: 'Test 1' }, 
     { title: 'Test template 2', content: 'Test 2' } 
     ], 
     content_css: ['//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css', 
     '//www.tinymce.com/css/codepen.min.css' 
     ] 
}); 

只要複製粘貼一些代碼TinyMCE的編輯器,這個變化將迫使在<pre>標籤下複製。

請注意,使用enter將在現有標籤中創建一個新行,同時使用shift + enter將會創建一個新塊。當你不得不經常在標籤之間切換時,使用shift + enter的技巧可能對你很有用。