2015-09-05 14 views
5

Sto usando l'ultimo TinyMCE che è ottimo, ma l'unico problema che ho è quando le persone postano degli esempi di codice. Non importa se lo pubblicano in un formato PRE o solo normalmente.Stop TinyMCE Stripping dei rientri quando si incolla il codice

TinyMCE rimuove tutti i rientri (schede) e rende difficile la lettura, qualcuno qui è riuscito a risolvere il problema? Esempi di codice/campioni sarebbero apprezzati.

risposta

2

È questo il tuo dopo. Sembra funzionare correttamente su questo JSFiddle

HTML

<form> 
    <textarea id='editor_instance_1'></textarea> 
</form> 
<button id='post-code-btn'>Post Code</button> 
<div id='post-area'></div> 

JS

//create instance of an mce editor 
var ed = new tinymce.Editor('editor_instance_1', { 
    //add custom formats 
    style_formats: [ 
     {title: 'Code', block: 'pre', styles: {'color': '#000', 'font-size': '11px'}}, 
     {title: 'Text', block: 'p', styles: {'color': '#ff0000', 'font-size': '16px'}} 
    ], 
    //force the starting block to pre 
    forced_root_block : 'pre'  
}, tinymce.EditorManager); 

//render the editor on screen 
ed.render(); 

var postButton = document.getElementById('post-code-btn'); 
var postArea = document.getElementById('post-area'); 

postButton.onclick = function(){ 
    //get html structure from the editor instance 
    var code = ed.getBody().innerHTML; 
    //simulate posting of html 
    new Request.HTML({ 
     url: '/echo/html/', 
     data: { 
      html: code, 
      delay: 0 
     }, 
     type: 'post', 
     update: 'post-area',  
    }).send(); 
} 

ho incollato nel codice provenienti da più fonti, tra cui Eclipse, SO e JSFiddle.