123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>CodeMirror: Linter Demo</title>
- <link rel="stylesheet" href="../lib/codemirror.css">
- <script src="../lib/codemirror.js"></script>
- <script src="../mode/javascript/javascript.js"></script>
- <script src="http://ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js"></script>
- <script src="https://raw.github.com/zaach/jsonlint/79b553fb65c192add9066da64043458981b3972b/lib/jsonlint.js"></script>
- <link rel="stylesheet" href="../doc/docs.css">
- <link rel="stylesheet" href="../addon/lint/lint.css">
- <script src="../addon/lint/lint.js"></script>
- <script src="../addon/lint/javascript-lint.js"></script>
- <script src="../addon/lint/json-lint.js"></script>
- <style type="text/css">
- .CodeMirror {border: 1px solid black;}
- </style>
- </head>
- <body>
- <h1>CodeMirror: Linter Demo</h1>
- <p><textarea id="code-js">var widgets = []
- function updateHints() {
- editor.operation(function(){
- for (var i = 0; i < widgets.length; ++i)
- editor.removeLineWidget(widgets[i]);
- widgets.length = 0;
- JSHINT(editor.getValue());
- for (var i = 0; i < JSHINT.errors.length; ++i) {
- var err = JSHINT.errors[i];
- if (!err) continue;
- var msg = document.createElement("div");
- var icon = msg.appendChild(document.createElement("span"));
- icon.innerHTML = "!!";
- icon.className = "lint-error-icon";
- msg.appendChild(document.createTextNode(err.reason));
- msg.className = "lint-error";
- widgets.push(editor.addLineWidget(err.line - 1, msg, {coverGutter: false, noHScroll: true}));
- }
- });
- var info = editor.getScrollInfo();
- var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
- if (info.top + info.clientHeight < after)
- editor.scrollTo(null, after - info.clientHeight + 3);
- }
- </textarea></p>
- <p><textarea id="code-json">[
- {
- _id: "post 1",
- "author": "Bob",
- "content": "...",
- "page_views": 5
- },
- {
- "_id": "post 2",
- "author": "Bob",
- "content": "...",
- "page_views": 9
- },
- {
- "_id": "post 3",
- "author": "Bob",
- "content": "...",
- "page_views": 8
- }
- ]
- </textarea></p>
- <script>
- var editor = CodeMirror.fromTextArea(document.getElementById("code-js"), {
- lineNumbers: true,
- mode: "javascript",
- gutters: ["CodeMirror-lint-markers"],
- lintWith: CodeMirror.javascriptValidator
- });
- var editor_json = CodeMirror.fromTextArea(document.getElementById("code-json"), {
- lineNumbers: true,
- mode: "application/json",
- gutters: ["CodeMirror-lint-markers"],
- lintWith: CodeMirror.jsonValidator
- });
- </script>
- </body>
- </html>
|