diff --git a/lib/ace/mode/behaviour/html.js b/lib/ace/mode/behaviour/html.js
index e7a74cf9..1d500e0f 100644
--- a/lib/ace/mode/behaviour/html.js
+++ b/lib/ace/mode/behaviour/html.js
@@ -38,14 +38,9 @@ var TokenIterator = require("../../token_iterator").TokenIterator;
var voidElements = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
function hasType(token, type) {
- var hasType = true;
- var typeList = token.type.split('.');
- var needleList = type.split('.');
- needleList.forEach(function(needle){
- if (typeList.indexOf(needle) == -1) {
- hasType = false;
- return false;
- }
+ var tokenTypes = token.type.split('.');
+ return type.split('.').every(function(type){
+ return (tokenTypes.indexOf(type) !== -1);
});
return hasType;
}
@@ -60,7 +55,7 @@ var HtmlBehaviour = function () {
var iterator = new TokenIterator(session, position.row, position.column);
var token = iterator.getCurrentToken();
- if (hasType(token, 'string') && iterator.getCurrentTokenColumn() + token.value.length > position.column)
+ if (token && hasType(token, 'string') && iterator.getCurrentTokenColumn() + token.value.length > position.column)
return;
var atCursor = false;
if (!token || !hasType(token, 'meta.tag') && !(hasType(token, 'text') && token.value.match('/'))){
@@ -70,8 +65,8 @@ var HtmlBehaviour = function () {
} else {
atCursor = true;
}
- if (!token || !hasType(token, 'meta.tag-name') || iterator.stepBackward().value.match('/')) {
- return
+ if (!token || !hasType(token, 'meta.tag.name') || iterator.stepBackward().value.match('/')) {
+ return;
}
var element = token.value;
if (atCursor){
diff --git a/lib/ace/mode/html_highlight_rules.js b/lib/ace/mode/html_highlight_rules.js
index d80ec2de..fdd7ec6e 100644
--- a/lib/ace/mode/html_highlight_rules.js
+++ b/lib/ace/mode/html_highlight_rules.js
@@ -35,8 +35,7 @@ var oop = require("../lib/oop");
var lang = require("../lib/lang");
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
-var xmlUtil = require("./xml_util");
-var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
+var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
var tagMap = lang.createMap({
a : 'anchor',
@@ -58,81 +57,66 @@ var tagMap = lang.createMap({
});
var HtmlHighlightRules = function() {
+ XmlHighlightRules.call(this);
- // regexp must not have capturing parentheses
- // regexps are ordered -> the first match is used
- this.$rules = {
- start : [{
- token : "text",
- regex : "<\\!\\[CDATA\\[",
- next : "cdata"
+ this.addRules({
+ attributes: [{
+ include : "space"
}, {
- token : "xml-pe",
- regex : "<\\?.*?\\?>"
+ token : "entity.other.attribute-name",
+ regex : "[-_a-zA-Z0-9:]+"
}, {
- token : "comment",
- regex : "<\\!--",
- next : "comment"
+ token : "keyword.operator.separator",
+ regex : "=",
+ push : [{
+ include: "space",
+ }, {
+ token : "string",
+ regex : "[^<>='\"`\\s]+",
+ next : "pop"
+ }, {
+ token : "empty",
+ regex : "",
+ next : "pop"
+ }]
}, {
- token : "xml-pe",
- regex : "<\\!.*?>"
- }, {
- token : "meta.tag",
- regex : "<(?=script\\b)",
- next : "script"
- }, {
- token : "meta.tag",
- regex : "<(?=style\\b)",
- next : "style"
- }, {
- token : "meta.tag", // opening tag
- regex : "<\\/?(?=\\S)",
- next : "tag"
- }, {
- token : "text",
- regex : "\\s+"
- }, {
- token : "constant.character.entity",
- regex : "(?:[0-9]+;)|(?:[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
+ include : "string"
}],
-
- cdata : [ {
- token : "text",
- regex : "\\]\\]>",
- next : "start"
- } ],
-
- comment : [ {
- token : "comment",
- regex : ".*?-->",
- next : "start"
+ tag: [{
+ token : function(start, tag) {
+ var group = tagMap[tag];
+ return ["punctuation.meta.tag.begin",
+ "meta.tag.name" + (group ? "." + group : "")];
+ },
+ regex : "(<)([-_a-zA-Z0-9:]+)",
+ next: "start_tag_stuff"
}, {
- defaultToken : "comment"
- } ]
- };
-
- xmlUtil.tag(this.$rules, "tag", "start", tagMap);
- xmlUtil.tag(this.$rules, "style", "css-start", tagMap);
- xmlUtil.tag(this.$rules, "script", "js-start", tagMap);
-
- this.embedRules(JavaScriptHighlightRules, "js-", [{
- token: "comment",
- regex: "\\/\\/.*(?=<\\/script>)",
- next: "tag"
- }, {
- token: "meta.tag",
- regex: "<\\/(?=script)",
- next: "tag"
- }]);
-
- this.embedRules(CssHighlightRules, "css-", [{
- token: "meta.tag",
- regex: "<\\/(?=style)",
- next: "tag"
- }]);
+ token : function(start, tag) {
+ var group = tagMap[tag];
+ return ["punctuation.meta.tag.begin",
+ "meta.tag.name" + (group ? "." + group : "")];
+ },
+ regex : "()([-_a-zA-Z0-9:]+)",
+ next: "end_tag_stuff"
+ }],
+ start_tag_stuff: [
+ {include : "attributes"},
+ {token : "punctuation.meta.tag.end", regex : "/?>", next : "start"}
+ ],
+ end_tag_stuff: [
+ {include : "space"},
+ {token : "punctuation.meta.tag.end", regex : ">", next : "start"}
+ ]
+ });
+
+ this.embedTagRules(CssHighlightRules, "css-", "style");
+ this.embedTagRules(JavaScriptHighlightRules, "js-", "script");
+
+ if (this.constructor === HtmlHighlightRules)
+ this.normalizeRules();
};
-oop.inherits(HtmlHighlightRules, TextHighlightRules);
+oop.inherits(HtmlHighlightRules, XmlHighlightRules);
exports.HtmlHighlightRules = HtmlHighlightRules;
});