Stop TinyMCE padding when pasting code

I am using the latest TinyMCE, which is wonderful, but the only problem I am having is when people send code samples. It doesn't matter if they publish it in PRE format or just fine.

TinyMCE removes all indentation (tabs) and makes it difficult to read, can anyone handle this here? Code examples / samples will be appreciated.

+5
source share
1 answer

This is what your after. It seems to work correctly on 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(); } 

I have inserted code from several sources, including eclipse, SO, and JSFiddle.

+2
source

All Articles