1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function(mod) {
|
9 | if (typeof exports == "object" && typeof module == "object")
|
10 | mod(require("../../lib/codemirror"));
|
11 | else if (typeof define == "function" && define.amd)
|
12 | define(["../../lib/codemirror"], mod);
|
13 | else
|
14 | mod(CodeMirror);
|
15 | })(function(CodeMirror) {
|
16 | "use strict";
|
17 |
|
18 | CodeMirror.registerHelper("lint", "json", function(text) {
|
19 | var found = [];
|
20 | if (!window.jsonlint) {
|
21 | if (window.console) {
|
22 | window.console.error("Error: window.jsonlint not defined, CodeMirror JSON linting cannot run.");
|
23 | }
|
24 | return found;
|
25 | }
|
26 |
|
27 |
|
28 | var jsonlint = window.jsonlint.parser || window.jsonlint
|
29 | jsonlint.parseError = function(str, hash) {
|
30 | var loc = hash.loc;
|
31 | found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
32 | to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
33 | message: str});
|
34 | };
|
35 | try { jsonlint.parse(text); }
|
36 | catch(e) {}
|
37 | return found;
|
38 | });
|
39 |
|
40 | });
|