Skip to content

Instantly share code, notes, and snippets.

@sliminality
Created November 18, 2015 20:37
Show Gist options
  • Save sliminality/fc3fdf3680421029806d to your computer and use it in GitHub Desktop.
Save sliminality/fc3fdf3680421029806d to your computer and use it in GitHub Desktop.
Formatting source with CodeMirror
// 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