forked from highlightjs/highlight.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted export-related scripting to export.js
- Loading branch information
Showing
2 changed files
with
31 additions
and
32 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Highlighted code export © Vladimir Gubarkov <[email protected]> | ||
String.prototype.escape = function() { | ||
return this.replace(/&/gm, '&').replace(/</gm, '<').replace(/>/gm, '>'); | ||
}; | ||
|
||
function ExportDoIt() { | ||
var export_from = document.getElementById("export_from"); | ||
var export_to = document.getElementById("export_to"); | ||
var export_view = document.getElementById("export_view"); | ||
var selector = document.getElementById("langSelector"); | ||
var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase(); | ||
if (selectedLang) { | ||
export_view.innerHTML = '<pre><code class="' + selectedLang + '">' + export_from.value.escape() + "</code></pre>"; | ||
} else { // try auto | ||
export_view.innerHTML = '<pre><code>' + export_from.value.escape() + "</code></pre>"; | ||
} | ||
hljs.highlightBlock(export_view.firstChild.firstChild); | ||
export_to.value = export_view.innerHTML; | ||
} | ||
|
||
function ExportCopyToBuffer(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); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,39 +63,8 @@ | |
$(document).ready(hljs.initHighlighting); | ||
</script> | ||
<script src="detection.js"></script> | ||
<script src="export.js"></script> | ||
|
||
<script> | ||
// Highlighted code export © Vladimir Gubarkov <[email protected]> | ||
String.prototype.escape = function() { | ||
return this.replace(/&/gm, '&').replace(/</gm, '<').replace(/>/gm, '>'); | ||
}; | ||
|
||
function ExportDoIt() { | ||
var export_from = document.getElementById("export_from"); | ||
var export_to = document.getElementById("export_to"); | ||
var export_view = document.getElementById("export_view"); | ||
var selector = document.getElementById("langSelector"); | ||
var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase(); | ||
if (selectedLang) { | ||
export_view.innerHTML = '<pre><code class="' + selectedLang + '">' + export_from.value.escape() + "</code></pre>"; | ||
} else { // try auto | ||
export_view.innerHTML = '<pre><code>' + export_from.value.escape() + "</code></pre>"; | ||
} | ||
hljs.highlightBlock(export_view.firstChild.firstChild); | ||
export_to.value = export_view.innerHTML; | ||
} | ||
|
||
function ExportCopyToBuffer(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); | ||
} | ||
} | ||
</script> | ||
<body> | ||
<div id="header"> | ||
<h1><a href="https://highlight.js.org/">highlight.js</a> demo</h1> | ||
|