Javascript examples for CodeMirror:Configuration
Codemirror Auto Format after setValue
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="https://codemirror.net/2/lib/codemirror.css"> <script type="text/javascript" src="https://codemirror.net/2/lib/codemirror.js"></script> <script type="text/javascript" src="https://codemirror.net/2/lib/util/formatting.js"></script> <script type="text/javascript" src="https://codemirror.net/2/mode/css/css.js"></script> <script type="text/javascript" src="https://codemirror.net/2/mode/xml/xml.js"></script> <script type="text/javascript" src="https://codemirror.net/2/mode/htmlmixed/htmlmixed.js"></script> <script type="text/javascript" src="https://codemirror.net/2/mode/javascript/javascript.js"></script> <link rel="stylesheet" type="text/css" href="https://codemirror.net/2/doc/docs.css"> <style id="compiled-css" type="text/css"> .CodeMirror {/* w ww. j a v a 2s. com*/ border: 1px solid #eee; } td { padding-right: 20px; } </style> </head> <body> <input type="button" onclick="autoFormatSelection()" value="autoFormatSelection"> <input type="button" onclick="commentSelection(true)" value="commentSelection"> <form> <textarea id="code" name="code"> <script> function (s,e){ for(var i=0; i < 1; i++) test("test();a=1");} </script> <script> function test(c){ for (var i = 0; i < 10; i++){ process("a.b();c = null;", 300);} } </script> <table><tr><td>test 1</td></tr><tr><td>test 2</td></tr></table> <script> function test() { return 1;} </script> <style> .test { font-size: medium; font-family: monospace; } </style></textarea> </form> <script type="text/javascript"> var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, mode: "htmlmixed", extraKeys:{"Shift-Tab":autoFormatSelection} }); function getSelectedRange() { return { from: editor.getCursor(true), to: editor.getCursor(false) }; } function autoFormatSelection() { var range = getSelectedRange(); editor.autoFormatRange(range.from, range.to); } function commentSelection(isComment) { var range = getSelectedRange(); editor.commentRange(isComment, range.from, range.to); } </script> </body> </html>