-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmain.js
More file actions
83 lines (63 loc) · 3.1 KB
/
main.js
File metadata and controls
83 lines (63 loc) · 3.1 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window, W3CValidator */
define(function (require, exports, module) {
'use strict';
var CodeInspection = brackets.getModule("language/CodeInspection"),
AppInit = brackets.getModule("utils/AppInit"),
Menus = brackets.getModule("command/Menus"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager");
var COMMAND_ID = "w3cvalidator_refresh",
PROVIDER_ID = "W3CValidation";
var Strings = require("strings");
require('w3cvalidator');
function _handleValidation(text, fullPath) {
var response = new $.Deferred();
var result = {errors:[]};
W3CValidator.validate(text, function (res) {
var messages = res.messages;
if (messages.length) {
messages.forEach(function (item) {
//console.log('W3CValidation messsage ',item);
var type = CodeInspection.Type.ERROR;
if (item.type === "warning")
type = CodeInspection.Type.WARNING;
/*
The new validator returns 2 info messages that look to be BS.
They are:
"The Content-Type was “text/html”. Using the HTML parser.
"Using the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support."
For now, we'll just delete them
*/
if(item.message == 'The Content-Type was “text/html”. Using the HTML parser.' ||
item.message == 'Using the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support.') {
} else {
result.errors.push({
pos: {line:item.lastLine-1, ch:0},
message:item.message,
type:type
});
}
});
}
response.resolve(result);
});
return response.promise();
}
function _refreshValidation() {
var currentDoc = DocumentManager.getCurrentDocument();
currentDoc.notifySaved();
}
AppInit.appReady(function () {
CodeInspection.register("html", {
//name: "W3CValidation",
name: PROVIDER_ID,
scanFileAsync: _handleValidation
});
});
// Command
CommandManager.register(Strings.REFRESH_W3C_VALIDATION, COMMAND_ID, _refreshValidation);
// Menu
var editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
editMenu.addMenuItem(COMMAND_ID, "F9");
});