add support for multiline attributes in html and xml modes
This commit is contained in:
parent
f9bf9bfc9a
commit
ef8973a8f8
3 changed files with 85 additions and 24 deletions
|
|
@ -47,6 +47,36 @@ var HtmlHighlightRules = function() {
|
|||
// regexp must not have capturing parentheses
|
||||
// regexps are ordered -> the first match is used
|
||||
|
||||
function string(state) {
|
||||
return [
|
||||
{
|
||||
token : "string",
|
||||
regex : '".*?"'
|
||||
}, {
|
||||
token : "string", // multi line string start
|
||||
regex : '["].*$',
|
||||
next : state + "-qqstring"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : "'.*?'"
|
||||
}, {
|
||||
token : "string", // multi line string start
|
||||
regex : "['].*$",
|
||||
next : state + "-qstring"
|
||||
}]
|
||||
}
|
||||
|
||||
function multiLineString(quote, state) {
|
||||
return [{
|
||||
token : "string",
|
||||
regex : ".*" + quote,
|
||||
next : state
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '.+'
|
||||
}]
|
||||
}
|
||||
|
||||
this.$rules = {
|
||||
start : [ {
|
||||
token : "text",
|
||||
|
|
@ -89,13 +119,7 @@ var HtmlHighlightRules = function() {
|
|||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '".*?"'
|
||||
}, {
|
||||
token : "string",
|
||||
regex : "'.*?'"
|
||||
} ],
|
||||
}].concat(string("script")),
|
||||
|
||||
css : [ {
|
||||
token : "text",
|
||||
|
|
@ -107,13 +131,7 @@ var HtmlHighlightRules = function() {
|
|||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '".*?"'
|
||||
}, {
|
||||
token : "string",
|
||||
regex : "'.*?'"
|
||||
} ],
|
||||
}].concat(string("css")),
|
||||
|
||||
tag : [ {
|
||||
token : "text",
|
||||
|
|
@ -125,14 +143,15 @@ var HtmlHighlightRules = function() {
|
|||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '".*?"'
|
||||
}, {
|
||||
token : "string",
|
||||
regex : "'.*?'"
|
||||
} ],
|
||||
|
||||
}].concat(string("tag")),
|
||||
|
||||
"css-qstring": multiLineString("'", "css"),
|
||||
"css-qqstring": multiLineString('"', "css"),
|
||||
"script-qstring": multiLineString("'", "script"),
|
||||
"script-qqstring": multiLineString('"', "script"),
|
||||
"tag-qstring": multiLineString("'", "tag"),
|
||||
"tag-qqstring": multiLineString('"', "tag"),
|
||||
|
||||
cdata : [ {
|
||||
token : "text",
|
||||
regex : "\\]\\]>",
|
||||
|
|
|
|||
|
|
@ -66,7 +66,23 @@ module.exports = {
|
|||
assert.equal("text", tokens[8].type);
|
||||
assert.equal("keyword", tokens[9].type);
|
||||
assert.equal("text", tokens[10].type);
|
||||
}
|
||||
},
|
||||
|
||||
"test: tokenize multiline attribute value with double quotes": function() {
|
||||
var line1 = this.tokenizer.getLineTokens('<a href="abc', "start");
|
||||
var t1 = line1.tokens;
|
||||
var t2 = this.tokenizer.getLineTokens('def">', line1.state).tokens;
|
||||
assert.equal(t1[t1.length-1].type, "string");
|
||||
assert.equal(t2[0].type, "string");
|
||||
},
|
||||
|
||||
"test: tokenize multiline attribute value with single quotes": function() {
|
||||
var line1 = this.tokenizer.getLineTokens('<a href=\'abc', "start");
|
||||
var t1 = line1.tokens;
|
||||
var t2 = this.tokenizer.getLineTokens('def\'>', line1.state).tokens;
|
||||
assert.equal(t1[t1.length-1].type, "string");
|
||||
assert.equal(t2[0].type, "string");
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,11 +82,37 @@ var XmlHighlightRules = function() {
|
|||
}, {
|
||||
token : "string",
|
||||
regex : '".*?"'
|
||||
}, {
|
||||
token : "string", // multi line string start
|
||||
regex : '["].*$',
|
||||
next : "qqstring"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : "'.*?'"
|
||||
} ],
|
||||
}, {
|
||||
token : "string", // multi line string start
|
||||
regex : "['].*$",
|
||||
next : "qstring"
|
||||
}],
|
||||
|
||||
qstring: [{
|
||||
token : "string",
|
||||
regex : ".*'",
|
||||
next : "tag"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '.+'
|
||||
}],
|
||||
|
||||
qqstring: [{
|
||||
token : "string",
|
||||
regex : ".*\"",
|
||||
next : "tag"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '.+'
|
||||
}],
|
||||
|
||||
cdata : [ {
|
||||
token : "text",
|
||||
regex : "\\]\\]>",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue