Created
November 9, 2009 08:48
-
-
Save madebysofa/229798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.escape = function() { | |
return this.replace(/&/gm, '&').replace(/</gm, '<').replace(/>/gm, '>'); | |
} | |
function doIt() { | |
var viewDiv = document.getElementById("highlight-view"); | |
var t1 = document.getElementById("t1"); | |
var t2 = document.getElementById("t2"); | |
var selector = document.getElementById("langSelector"); | |
var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase(); | |
if(selectedLang) { | |
viewDiv.innerHTML = '<pre><code class="'+selectedLang+'">'+t1.value.escape()+"</code></pre>"; | |
} else { // try auto | |
viewDiv.innerHTML = '<pre><code>' + t1.value.escape() + "</code></pre>"; | |
} | |
hljs.highlightBlock(viewDiv.firstChild.firstChild); | |
t2.value = viewDiv.innerHTML; | |
} | |
function copyToBuffer(textToCopy) { | |
if (window.clipboardData) { // IE | |
window.clipboardData.setData("Text", textToCopy); | |
} else if (window.netscape) { // FF | |
// from http://developer.mozilla.org/en/docs/Using_the_Clipboard | |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); | |
var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); | |
gClipboardHelper.copyString(textToCopy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment