web编辑器codemirror使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link href="https://cdn.bootcss.com/codemirror/5.28.0/theme/seti.min.css" rel="stylesheet"> <link href="https://cdn.bootcss.com/codemirror/5.28.0/theme/solarized.min.css" rel="stylesheet"> <link href="https://cdn.bootcss.com/codemirror/5.28.0/codemirror.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/codemirror/5.28.0/codemirror.min.js"></script> <script src="https://cdn.bootcss.com/codemirror/5.28.0/mode/clike/clike.min.js"></script> </head> <body> <textarea id="myCode">#input your Code here#</textarea> <script type="text/javascript"> var editor = CodeMirror.fromTextArea(document.getElementById("myCode"), { lineNumbers: true, mode: "javascript", theme: "seti", indentUnit: 4, smartIndent: true, lineWiseCopyCut: false, dragDrop: false, autofocus: true }); </script> </body> </html>
|
加入选择主题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <link href="https://cdn.bootcss.com/codemirror/5.28.0/theme/seti.min.css" rel="stylesheet"> <link href="https://cdn.bootcss.com/codemirror/5.28.0/theme/solarized.min.css" rel="stylesheet"> <link href="https://cdn.bootcss.com/codemirror/5.28.0/codemirror.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/codemirror/5.28.0/codemirror.min.js"></script> <script src="https://cdn.bootcss.com/codemirror/5.28.0/mode/clike/clike.min.js"></script> <link href="https://cdn.bootcss.com/codemirror/5.28.0/theme/base16-light.min.css" rel="stylesheet"> </head> <body> <h2>Theme Demo</h2> <textarea id="jsoncode" name="jsoncode" disabled="disabled" readonly="readonly">#code#</textarea> <p>选择主题: <select id="select" onchange="selectTheme()"> <option selected>default</option> <option>solarized</option> <option>seti</option> <option>base16-light</option> </select> </p> <script> var editor = CodeMirror.fromTextArea(document.getElementById("jsoncode"), { lineNumbers: true, lineWrapping: true, styleActiveLine: true, matchBrackets: true, readOnly: true, theme: "solarized" }); var input = document.getElementById("select"); function selectTheme() { var theme = input.options[input.selectedIndex].textContent; editor.setOption("theme", theme); location.hash = "#" + theme; } var choice = (location.hash && location.hash.slice(1)) || (document.location.search && decodeURIComponent(document.location.search.slice(1))); if (choice) { input.value = choice; editor.setOption("theme", choice); } CodeMirror.on(window, "hashchange", function() { var theme = location.hash.slice(1); if (theme) { input.value = theme; selectTheme(); } }); </script> </body> </html>
|
支持语言列表
http://codemirror.net/mode/index.html