handle void elements in html folding
This commit is contained in:
parent
d8faf048bc
commit
285afeb4f2
2 changed files with 52 additions and 2 deletions
|
|
@ -771,6 +771,26 @@ Folding.commonFoldingRules = {
|
||||||
"indentation": null,
|
"indentation": null,
|
||||||
|
|
||||||
"xml": {
|
"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) {
|
getFoldWidget: function(row) {
|
||||||
var tags = this.getTokens(row, row)[0].tokens
|
var tags = this.getTokens(row, row)[0].tokens
|
||||||
.filter(function(token) {
|
.filter(function(token) {
|
||||||
|
|
@ -786,8 +806,9 @@ Folding.commonFoldingRules = {
|
||||||
|
|
||||||
var fold = tags[0];
|
var fold = tags[0];
|
||||||
|
|
||||||
if (!fold)
|
if (!fold || Folding.commonFoldingRules.xml.voidElements[fold])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fold.charAt(0) == "/")
|
if (fold.charAt(0) == "/")
|
||||||
return "end";
|
return "end";
|
||||||
|
|
||||||
|
|
@ -805,12 +826,38 @@ Folding.commonFoldingRules = {
|
||||||
var step = "stepForward";
|
var step = "stepForward";
|
||||||
var isBack = false;
|
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
|
||||||
|
// };
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var token = iterator.getCurrentToken();
|
var token = iterator.getCurrentToken();
|
||||||
|
|
||||||
var value = token.value.trim();
|
var value = token.value.trim();
|
||||||
if (token && token.type == "meta.tag" && token.value !== ">") {
|
if (token && token.type == "meta.tag" && token.value !== ">") {
|
||||||
var tagName = value.replace(/^[<\s]*|[\s*>]$/g, "");
|
var tagName = value.replace(/^[<\s]*|[\s*>]$/g, "");
|
||||||
|
if (Folding.commonFoldingRules.xml.voidElements[tagName])
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!start) {
|
if (!start) {
|
||||||
if (tagName.charAt(0) == "/") {
|
if (tagName.charAt(0) == "/") {
|
||||||
tagName = tagName.slice(1);
|
tagName = tagName.slice(1);
|
||||||
|
|
@ -823,6 +870,7 @@ Folding.commonFoldingRules = {
|
||||||
column: iterator.getCurrentTokenColumn() + (isBack ? 0 : value.length + 1)
|
column: iterator.getCurrentTokenColumn() + (isBack ? 0 : value.length + 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("push", tagName)
|
||||||
stack.push(tagName);
|
stack.push(tagName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -835,6 +883,7 @@ Folding.commonFoldingRules = {
|
||||||
|
|
||||||
if (close) {
|
if (close) {
|
||||||
if (stack[stack.length-1] == tagName) {
|
if (stack[stack.length-1] == tagName) {
|
||||||
|
console.log("pop", tagName)
|
||||||
stack.pop();
|
stack.pop();
|
||||||
if (stack.length == 0) {
|
if (stack.length == 0) {
|
||||||
end = {
|
end = {
|
||||||
|
|
@ -852,6 +901,7 @@ Folding.commonFoldingRules = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
console.log("push", tagName)
|
||||||
stack.push(tagName);
|
stack.push(tagName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,5 +85,5 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof module !== "undefined" && module === require.main) {
|
if (typeof module !== "undefined" && module === require.main) {
|
||||||
require("asyncjs").test.testcase(module.exports).exec()
|
require("asyncjs").test.testcase(module.exports).exec();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue