PageRenderTime 16ms CodeModel.GetById 8ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/scalate-presentation/src/highlight/export.html

http://github.com/scalate/scalate
HTML | 115 lines | 104 code | 4 blank | 7 comment | 0 complexity | a71e36e983a2076f08be84ed00bc42bd MD5 | raw file
  1<!-- saved from url=(0013)about:internet -->
  2<!-- ^^^ This is for IE not to show security warning for local files,
  3see http://www.microsoft.com/technet/prodtechnol/winxppro/maintain/sp2brows.mspx-->
  4
  5<!--
  6Highlighted code export
  7Copyright (c) Vladimir Gubarkov <xonixx@gmail.com>
  8-->
  9
 10<html>
 11    <head>
 12        <title>Highlited code export</title>
 13        <link rel="stylesheet" href="styles/default.css">
 14        <meta charset="utf-8">
 15        <style type="text/css">
 16            #t1, #t2 { width: 100%;}
 17            tr { vertical-align: top; }
 18            address { margin-top: 4em; }
 19        </style>
 20        <script src="highlight.js"></script>
 21        <script src="languages/cs.js"></script>
 22        <script src="languages/python.js"></script>
 23        <script src="languages/mel.js"></script>
 24        <script src="languages/perl.js"></script>
 25        <script src="languages/axapta.js"></script>
 26        <script src="languages/cpp.js"></script>
 27        <script src="languages/sql.js"></script>
 28        <script src="languages/smalltalk.js"></script>
 29        <script src="languages/profile.js"></script>
 30        <script src="languages/bash.js"></script>
 31        <script src="languages/html-xml.js"></script>
 32        <script src="languages/renderman.js"></script>
 33        <script src="languages/1c.js"></script>
 34        <script src="languages/delphi.js"></script>
 35        <script src="languages/dos.js"></script>
 36        <script src="languages/django.js"></script>
 37        <script src="languages/vbscript.js"></script>
 38        <script src="languages/ini.js"></script>
 39        <script src="languages/apache.js"></script>
 40        <script src="languages/ruby.js"></script>
 41        <script src="languages/css.js"></script>
 42        <script src="languages/lisp.js"></script>
 43        <script src="languages/java.js"></script>
 44        <script src="languages/javascript.js"></script>
 45        <script src="languages/php.js"></script>
 46        <script src="languages/diff.js"></script>
 47        <script src="languages/avrasm.js"></script>
 48        <script src="languages/parser3.js"></script>
 49        <script>hljs.initHighlightingOnLoad();</script>
 50    </head>
 51    <body>
 52        <script type="text/javascript">
 53            String.prototype.escape = function() {
 54                return this.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
 55            }
 56
 57            function doIt() {
 58                var viewDiv = document.getElementById("highlight-view");
 59                var t1 = document.getElementById("t1");
 60                var t2 = document.getElementById("t2");
 61                var selector = document.getElementById("langSelector");
 62                var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase();
 63                if(selectedLang) {
 64                    viewDiv.innerHTML = '<pre><code class="'+selectedLang+'">'+t1.value.escape()+"</code></pre>";
 65                } else { // try auto
 66                    viewDiv.innerHTML = '<pre><code>' + t1.value.escape() + "</code></pre>";
 67                }
 68                hljs.highlightBlock(viewDiv.firstChild.firstChild);
 69                t2.value = viewDiv.innerHTML;
 70            }
 71
 72            function copyToBuffer(textToCopy) {
 73                if (window.clipboardData) { // IE
 74                    window.clipboardData.setData("Text", textToCopy);
 75                } else if (window.netscape) { // FF
 76                    // from http://developer.mozilla.org/en/docs/Using_the_Clipboard
 77                    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 78                    var gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
 79                    gClipboardHelper.copyString(textToCopy);
 80                }
 81            }
 82        </script>
 83        <script type="text/javascript">
 84            var langSelectorHtml = '<label>Language <select id="langSelector">';
 85            langSelectorHtml += '<option value="">Auto</option>';
 86            for (var i in hljs.LANGUAGES) {
 87                if (hljs.LANGUAGES.hasOwnProperty(i))
 88                    langSelectorHtml += '<option value=\"'+i+'\">'+i.charAt(0).toUpperCase()+i.substr(1)+'</option>';
 89            }
 90            langSelectorHtml += '</select></label>';
 91            document.write(langSelectorHtml);
 92        </script>
 93        <table width="100%">
 94            <tr>
 95                <td><textarea rows="20" cols="50" id="t1"></textarea></td>
 96                <td><textarea rows="20" cols="50" id="t2"></textarea></td>
 97            </tr>
 98            <tr>
 99                <td>Write a code snippet</td>
100                <td>Get HTML to paste anywhere (for actual styles and colors see sample.css)</td>
101            </tr>
102        </table>
103        <table width="98%">
104            <tr>
105                <td><input type="button" value="Export &rarr;" onclick="doIt()"/></td>
106                <td align="right"><input type="button" value="Copy to buffer" onclick="copyToBuffer(document.getElementById('t2').value);"/></td>
107            </tr>
108        </table>
109        <div id="highlight-view"></div>
110        <address>
111          Export script: <a href="mailto:xonixx@gmail.com">Vladimir Gubarkov</a><br>
112          Highlighting: <a href="http://softwaremaniacs.org/soft/highlight/">highlight.js</a>
113        </address>
114    </body>
115</html>