Move HTML tags out of xml_util

This commit is contained in:
Daniil Kostion 2012-07-02 05:40:13 +10:00
commit 70cda1375b
2 changed files with 26 additions and 33 deletions

View file

@ -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
@ -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",

View file

@ -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",
@ -81,7 +71,7 @@ function multiLineString(quote, state) {
}];
}
exports.tag = function(states, name, nextState) {
exports.tag = function(states, name, nextState, tagMap) {
states[name] = [{
token : "text",
regex : "\\s+"
@ -89,25 +79,9 @@ exports.tag = function(states, name, nextState) {
//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";
}
},