Created
November 18, 2015 20:37
-
-
Save sliminality/fc3fdf3680421029806d to your computer and use it in GitHub Desktop.
Formatting source with CodeMirror
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
// Editor initialization | |
var area = $('textarea.text-editor'); // or whatever yours is called | |
editor = CodeMirror.fromTextArea(area.get(0), { | |
mode: {name: "xml", htmlMode: true}, // enables syntax highlighting, need to download the relevant modules | |
lineNumbers: true, | |
lineWrapping: true, | |
tabSize: 2 | |
}); | |
// Re-indent everything | |
// https://codemirror.net/doc/manual.html#event_change | |
editor.on("change", reindent(instance)); | |
var reindent = function(cm) { | |
var lines = cm.lineCount(); | |
for (var i = 0; i < lines; i++) { | |
cm.indentLine(i); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment