Move HTML tags out of xml_util
This commit is contained in:
parent
d23ffd89e4
commit
70cda1375b
2 changed files with 26 additions and 33 deletions
|
|
@ -44,6 +44,25 @@ var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScrip
|
||||||
var xmlUtil = require("./xml_util");
|
var xmlUtil = require("./xml_util");
|
||||||
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
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() {
|
var HtmlHighlightRules = function() {
|
||||||
|
|
||||||
// regexp must not have capturing parentheses
|
// regexp must not have capturing parentheses
|
||||||
|
|
@ -113,9 +132,9 @@ var HtmlHighlightRules = function() {
|
||||||
} ]
|
} ]
|
||||||
};
|
};
|
||||||
|
|
||||||
xmlUtil.tag(this.$rules, "tag", "start");
|
xmlUtil.tag(this.$rules, "tag", "start", tagMap);
|
||||||
xmlUtil.tag(this.$rules, "style", "css-start");
|
xmlUtil.tag(this.$rules, "style", "css-start", tagMap);
|
||||||
xmlUtil.tag(this.$rules, "script", "js-start");
|
xmlUtil.tag(this.$rules, "script", "js-start", tagMap);
|
||||||
|
|
||||||
this.embedRules(JavaScriptHighlightRules, "js-", [{
|
this.embedRules(JavaScriptHighlightRules, "js-", [{
|
||||||
token: "comment",
|
token: "comment",
|
||||||
|
|
|
||||||
|
|
@ -38,16 +38,6 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"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) {
|
function string(state) {
|
||||||
return [{
|
return [{
|
||||||
token : "string",
|
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] = [{
|
states[name] = [{
|
||||||
token : "text",
|
token : "text",
|
||||||
regex : "\\s+"
|
regex : "\\s+"
|
||||||
|
|
@ -89,25 +79,9 @@ exports.tag = function(states, name, nextState) {
|
||||||
//token : "meta.tag",
|
//token : "meta.tag",
|
||||||
|
|
||||||
token : function(value) {
|
token : function(value) {
|
||||||
if ( value==='a' ) {
|
if (tagMap && tagMap[value]) {
|
||||||
return "meta.tag.anchor";
|
return "meta.tag" + '.' + tagMap[value];
|
||||||
}
|
} else {
|
||||||
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 {
|
|
||||||
return "meta.tag";
|
return "meta.tag";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue