-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.js
69 lines (51 loc) · 2.29 KB
/
main.js
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
/*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";
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;
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("Refresh W3C validation", COMMAND_ID, _refreshValidation);
// Menu
var editMenu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
editMenu.addMenuItem(COMMAND_ID);
});