Posted By

porquero on 02/09/12


Tagged

blogger prettyprint


Versions (?)

Add Pretty Print button for blogger editor


 / Published in: JavaScript
 

URL: http://porquero.blogspot.com

Add easily pre.prettyprint element for you code in the editor for blogger. Only ejecute this script when you manage your post.

Note: version alpha.

  1. _bt = document.createElement('button');
  2. document.body.appendChild(_bt);
  3. _bt.innerHTML='>Pretty Print!<';
  4. _bt.style.top='100px';
  5. _bt.style.position='absolute';
  6. _bt.onclick=function(){
  7. var range = document.getElementById('postingComposeBox').contentDocument.getSelection().getRangeAt(0),
  8. content = range.extractContents(),
  9. pre = document.createElement('pre');
  10.  
  11. pre.innerHTML = content.textContent;
  12. pre.className = 'prettyprint';
  13. var htmlContent = pre.innerHTML;
  14.  
  15. range.insertNode(pre);
  16. };

Report this snippet  

You need to login to post a comment.