Created
December 16, 2011 02:44
-
-
Save lyhcode/1484191 to your computer and use it in GitHub Desktop.
CodeMirror 2 runmode (highlight only)
This file contains hidden or 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
<div class="CodeMirror"> | |
<div class="CodeMirror-gutter"> | |
<div class="CodeMirror-gutter-text"> | |
<div id="numbers"></div> | |
</div> | |
</div> | |
<div class="CodeMirror-lines"> | |
<div style="position: relative; margin-left: 33px;"> | |
<pre id="output" class="cm-s-default"></pre> | |
</div> | |
</div> | |
</div> | |
<script type="text/javascript"> | |
var numbers = document.getElementById("numbers"); | |
var output = document.getElementById("output"); | |
var accum = [], gutter = [], size = 0; | |
var callback = function(string, style) { | |
if (string == "\n") { | |
accum.push("<br>"); | |
gutter.push('<pre>'+(++size)+'</pre>'); | |
} | |
else if (style) | |
accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>"); | |
else | |
accum.push(CodeMirror.htmlEscape(string)); | |
} | |
CodeMirror.runMode(document.getElementById("code").value, "text/x-rst", callback); | |
output.innerHTML = accum.join(''); | |
numbers.innerHTML = gutter.join(''); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codemirror.net/doc/releases.html
CodeMirror.htmlEscape
removed. userequire('xss-filters').inHTMLData
instead