This commit is contained in:
Fabian Jakobs 2011-12-01 16:51:55 +01:00
commit d2eeb44016
7 changed files with 163 additions and 10 deletions

View file

@ -8142,6 +8142,26 @@ Folding.commonFoldingRules = {
"indentation": null,
"xml": {
voidElements: {
"area": 1,
"base": 1,
"br": 1,
"col": 1,
"command": 1,
"embed": 1,
"hr": 1,
"img": 1,
"input": 1,
"keygen": 1,
"link": 1,
"meta": 1,
"param": 1,
"source": 1,
"track": 1,
"wbr": 1
},
getFoldWidget: function(row) {
var tags = this.getTokens(row, row)[0].tokens
.filter(function(token) {
@ -8157,8 +8177,9 @@ Folding.commonFoldingRules = {
var fold = tags[0];
if (!fold)
if (!fold || Folding.commonFoldingRules.xml.voidElements[fold])
return;
if (fold.charAt(0) == "/")
return "end";
@ -8176,12 +8197,39 @@ Folding.commonFoldingRules = {
var step = "stepForward";
var isBack = false;
// http://dev.w3.org/html5/spec/syntax.html#optional-tags
// TODO
// var optionalTags = {
// "html": 1,
// "head": 1,
// "body": 1,
// "li": 1,
// "dt": 1,
// "dd": 1,
// "p": 1,
// "rt": 1,
// "rp": 1,
// "optgroup": 1,
// "option": 1,
// "colgroup": 1,
// "thead": 1,
// "tbody": 1,
// "tfoot": 1,
// "tr": 1,
// "td": 1,
// "th": 1
// };
// limited XML parsing to find matching tag
do {
var token = iterator.getCurrentToken();
var value = token.value.trim();
if (token && token.type == "meta.tag" && token.value !== ">") {
var tagName = value.replace(/^[<\s]*|[\s*>]$/g, "");
if (Folding.commonFoldingRules.xml.voidElements[tagName])
continue;
if (!start) {
if (tagName.charAt(0) == "/") {
tagName = tagName.slice(1);
@ -8194,6 +8242,7 @@ Folding.commonFoldingRules = {
column: iterator.getCurrentTokenColumn() + (isBack ? 0 : value.length + 1)
};
// console.log("push", tagName)
stack.push(tagName);
}
else {
@ -8206,6 +8255,7 @@ Folding.commonFoldingRules = {
if (close) {
if (stack[stack.length-1] == tagName) {
// console.log("pop", tagName)
stack.pop();
if (stack.length == 0) {
end = {
@ -8219,10 +8269,11 @@ Folding.commonFoldingRules = {
}
}
else {
console.error("unmatched tags!", tagName, stack)
// console.error("unmatched tags!", tagName, stack)
}
}
else {
// console.log("push", tagName)
stack.push(tagName);
}
}

File diff suppressed because one or more lines are too long

View file

@ -11,7 +11,7 @@
Ace
version 0.2.0
commit 0c14c86c9408e3afe81f256116b4c6e663df6865
commit 5db6824f28f04b8b4df2566dada92b58d307dec8
-->

View file

@ -10049,6 +10049,26 @@ Folding.commonFoldingRules = {
"indentation": null,
"xml": {
voidElements: {
"area": 1,
"base": 1,
"br": 1,
"col": 1,
"command": 1,
"embed": 1,
"hr": 1,
"img": 1,
"input": 1,
"keygen": 1,
"link": 1,
"meta": 1,
"param": 1,
"source": 1,
"track": 1,
"wbr": 1
},
getFoldWidget: function(row) {
var tags = this.getTokens(row, row)[0].tokens
.filter(function(token) {
@ -10064,8 +10084,9 @@ Folding.commonFoldingRules = {
var fold = tags[0];
if (!fold)
if (!fold || Folding.commonFoldingRules.xml.voidElements[fold])
return;
if (fold.charAt(0) == "/")
return "end";
@ -10083,12 +10104,39 @@ Folding.commonFoldingRules = {
var step = "stepForward";
var isBack = false;
// http://dev.w3.org/html5/spec/syntax.html#optional-tags
// TODO
// var optionalTags = {
// "html": 1,
// "head": 1,
// "body": 1,
// "li": 1,
// "dt": 1,
// "dd": 1,
// "p": 1,
// "rt": 1,
// "rp": 1,
// "optgroup": 1,
// "option": 1,
// "colgroup": 1,
// "thead": 1,
// "tbody": 1,
// "tfoot": 1,
// "tr": 1,
// "td": 1,
// "th": 1
// };
// limited XML parsing to find matching tag
do {
var token = iterator.getCurrentToken();
var value = token.value.trim();
if (token && token.type == "meta.tag" && token.value !== ">") {
var tagName = value.replace(/^[<\s]*|[\s*>]$/g, "");
if (Folding.commonFoldingRules.xml.voidElements[tagName])
continue;
if (!start) {
if (tagName.charAt(0) == "/") {
tagName = tagName.slice(1);
@ -10101,6 +10149,7 @@ Folding.commonFoldingRules = {
column: iterator.getCurrentTokenColumn() + (isBack ? 0 : value.length + 1)
};
// console.log("push", tagName)
stack.push(tagName);
}
else {
@ -10113,6 +10162,7 @@ Folding.commonFoldingRules = {
if (close) {
if (stack[stack.length-1] == tagName) {
// console.log("pop", tagName)
stack.pop();
if (stack.length == 0) {
end = {
@ -10126,10 +10176,11 @@ Folding.commonFoldingRules = {
}
}
else {
console.error("unmatched tags!", tagName, stack)
// console.error("unmatched tags!", tagName, stack)
}
}
else {
// console.log("push", tagName)
stack.push(tagName);
}
}

File diff suppressed because one or more lines are too long

View file

@ -10003,6 +10003,26 @@ Folding.commonFoldingRules = {
"indentation": null,
"xml": {
voidElements: {
"area": 1,
"base": 1,
"br": 1,
"col": 1,
"command": 1,
"embed": 1,
"hr": 1,
"img": 1,
"input": 1,
"keygen": 1,
"link": 1,
"meta": 1,
"param": 1,
"source": 1,
"track": 1,
"wbr": 1
},
getFoldWidget: function(row) {
var tags = this.getTokens(row, row)[0].tokens
.filter(function(token) {
@ -10018,8 +10038,9 @@ Folding.commonFoldingRules = {
var fold = tags[0];
if (!fold)
if (!fold || Folding.commonFoldingRules.xml.voidElements[fold])
return;
if (fold.charAt(0) == "/")
return "end";
@ -10037,12 +10058,39 @@ Folding.commonFoldingRules = {
var step = "stepForward";
var isBack = false;
// http://dev.w3.org/html5/spec/syntax.html#optional-tags
// TODO
// var optionalTags = {
// "html": 1,
// "head": 1,
// "body": 1,
// "li": 1,
// "dt": 1,
// "dd": 1,
// "p": 1,
// "rt": 1,
// "rp": 1,
// "optgroup": 1,
// "option": 1,
// "colgroup": 1,
// "thead": 1,
// "tbody": 1,
// "tfoot": 1,
// "tr": 1,
// "td": 1,
// "th": 1
// };
// limited XML parsing to find matching tag
do {
var token = iterator.getCurrentToken();
var value = token.value.trim();
if (token && token.type == "meta.tag" && token.value !== ">") {
var tagName = value.replace(/^[<\s]*|[\s*>]$/g, "");
if (Folding.commonFoldingRules.xml.voidElements[tagName])
continue;
if (!start) {
if (tagName.charAt(0) == "/") {
tagName = tagName.slice(1);
@ -10055,6 +10103,7 @@ Folding.commonFoldingRules = {
column: iterator.getCurrentTokenColumn() + (isBack ? 0 : value.length + 1)
};
// console.log("push", tagName)
stack.push(tagName);
}
else {
@ -10067,6 +10116,7 @@ Folding.commonFoldingRules = {
if (close) {
if (stack[stack.length-1] == tagName) {
// console.log("pop", tagName)
stack.pop();
if (stack.length == 0) {
end = {
@ -10080,10 +10130,11 @@ Folding.commonFoldingRules = {
}
}
else {
console.error("unmatched tags!", tagName, stack)
// console.error("unmatched tags!", tagName, stack)
}
}
else {
// console.log("push", tagName)
stack.push(tagName);
}
}

File diff suppressed because one or more lines are too long