diff options
author | Hugues Hiegel <root@paranoid> | 2015-03-11 16:55:04 +0100 |
---|---|---|
committer | Hugues Hiegel <root@paranoid> | 2015-03-11 16:55:04 +0100 |
commit | 99f904adcc37d93c90defcd8ce898598e25be212 (patch) | |
tree | 60a6c7b7b9cf012d6c0e8dcf5c7f4fe0a5b6fc49 /codemirror_ui/lib/CodeMirror-2.3/demo/formatting.html | |
parent | b2034fdfec040a67988e543a911208ef2491ce7a (diff) |
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/demo/formatting.html')
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/demo/formatting.html | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/demo/formatting.html b/codemirror_ui/lib/CodeMirror-2.3/demo/formatting.html new file mode 100644 index 0000000..e4faf5f --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/demo/formatting.html @@ -0,0 +1,80 @@ +<!doctype html> +<html> + <head> + <title>CodeMirror: Formatting Demo</title> + <link rel="stylesheet" href="../lib/codemirror.css"> + <script src="../lib/codemirror.js"></script> + <script src="../lib/util/formatting.js"></script> + <script src="../mode/css/css.js"></script> + <script src="../mode/xml/xml.js"></script> + <script src="../mode/javascript/javascript.js"></script> + <script src="../mode/htmlmixed/htmlmixed.js"></script> + <link rel="stylesheet" href="../doc/docs.css"> + + <style type="text/css"> + .CodeMirror { + border: 1px solid #eee; + } + td { + padding-right: 20px; + } + </style> + </head> + <body> + <h1>CodeMirror: Formatting demo</h1> + + <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> + +<p>Select a piece of code and click one of the links below to apply automatic formatting to the selected text or comment/uncomment the selected text. Note that the formatting behavior depends on the current block's mode. + <table> + <tr> + <td> + <a href="javascript:autoFormatSelection()"> + Autoformat Selected + </a> + </td> + <td> + <a href="javascript:commentSelection(true)"> + Comment Selected + </a> + </td> + <td> + <a href="javascript:commentSelection(false)"> + Uncomment Selected + </a> + </td> + </tr> + </table> +</p> + <script> + var editor = CodeMirror.fromTextArea(document.getElementById("code"), { + lineNumbers: true, + mode: "htmlmixed" + }); + CodeMirror.commands["selectAll"](editor); + + 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> |