Skip to content

Commit

Permalink
add node index
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan committed May 16, 2017
1 parent 922de07 commit ab1c555
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions wxParse/html2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function html2json(html, bindName) {
images:[],
imageUrls:[]
};
var index = 0;
HTMLParser(html, {
start: function (tag, attrs, unary) {
//debug(tag, attrs, unary);
Expand All @@ -75,6 +76,17 @@ function html2json(html, bindName) {
tag: tag,
};

if (bufArray.length === 0) {
node.index = index.toString()
index += 1
} else {
var parent = bufArray[0];
if (parent.nodes === undefined) {
parent.nodes = [];
}
node.index = parent.index + '.' + parent.nodes.length
}

if (block[tag]) {
node.tagType = "block";
} else if (inline[tag]) {
Expand Down Expand Up @@ -209,6 +221,7 @@ function html2json(html, bindName) {
if (parent.nodes === undefined) {
parent.nodes = [];
}
node.index = parent.index + '.' + parent.nodes.length
parent.nodes.push(node);
}
},
Expand Down

0 comments on commit ab1c555

Please sign in to comment.