Created
May 4, 2016 10:43
-
-
Save tanraya/1d3e0ab778ef73830dac35a35c762f80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [ | |
['strong', 0, 5], | |
['span', 0, 5], | |
['em', 2, 5] | |
]; | |
var text = 'hello'; | |
//function vtext(t) {} | |
//function vnode(name, attrs, chldren) {} | |
/*[ | |
vnode('strong', {}, [ | |
vtext('he'), | |
vnode('span', {}, [ | |
vtext('llo') | |
]) | |
]) | |
]*/ | |
var vtree = []; | |
var current = null; | |
data.forEach(function(x) { | |
if (current == null || current !== null && !(x[1] >= current.start && x[2] <= current.end)) { | |
current = { | |
name: x[0], | |
children: [] | |
}; | |
vtree.push(current); | |
} else if (current !== null && x[1] >= current.start && x[2] <= current.end) { | |
var newCurrent = { | |
name: x[0], | |
children: [] | |
}; | |
current.children.push(newCurrent); | |
current = newCurrent; | |
} | |
}); | |
console.log(vtree); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment