Skip to content

Commit

Permalink
Move HTML tags out of xml_util
Browse files Browse the repository at this point in the history
  • Loading branch information
danyaPostfactum committed Jul 1, 2012
1 parent d23ffd8 commit 70cda13
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
25 changes: 22 additions & 3 deletions lib/ace/mode/html_highlight_rules.js
Expand Up @@ -44,6 +44,25 @@ var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScrip
var xmlUtil = require("./xml_util");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

var tagMap = {
a : 'anchor',
button : 'form',
form : 'form',
img : 'image',
input : 'form',
label : 'form',
script : 'script',
select : 'form',
textarea : 'form',
style : 'style',
table : 'table',
tbody : 'table',
td : 'table',
tfoot : 'table',
th : 'table',
tr : 'table'
};

var HtmlHighlightRules = function() {

// regexp must not have capturing parentheses
Expand Down Expand Up @@ -113,9 +132,9 @@ var HtmlHighlightRules = function() {
} ]
};

xmlUtil.tag(this.$rules, "tag", "start");
xmlUtil.tag(this.$rules, "style", "css-start");
xmlUtil.tag(this.$rules, "script", "js-start");
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",
Expand Down
34 changes: 4 additions & 30 deletions lib/ace/mode/xml_util.js
Expand Up @@ -38,16 +38,6 @@
define(function(require, exports, module) {
"use strict";

var lang = require("../lib/lang");

var formTags = lang.arrayToMap(
("button|form|input|label|select|textarea").split("|")
);

var tableTags = lang.arrayToMap(
("table|tbody|td|tfoot|th|tr").split("|")
);

function string(state) {
return [{
token : "string",
Expand Down Expand Up @@ -81,33 +71,17 @@ function multiLineString(quote, state) {
}];
}

exports.tag = function(states, name, nextState) {
exports.tag = function(states, name, nextState, tagMap) {
states[name] = [{
token : "text",
regex : "\\s+"
}, {
//token : "meta.tag",

token : function(value) {
if ( value==='a' ) {
return "meta.tag.anchor";
}
else if ( value==='img' ) {
return "meta.tag.image";
}
else if ( value==='script' ) {
return "meta.tag.script";
}
else if ( value==='style' ) {
return "meta.tag.style";
}
else if (formTags.hasOwnProperty(value.toLowerCase())) {
return "meta.tag.form";
}
else if (tableTags.hasOwnProperty(value.toLowerCase())) {
return "meta.tag.table";
}
else {
if (tagMap && tagMap[value]) {
return "meta.tag" + '.' + tagMap[value];
} else {
return "meta.tag";
}
},
Expand Down

0 comments on commit 70cda13

Please sign in to comment.