1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Add parse tree utility for collecting text

This commit is contained in:
Jermolene 2015-08-01 13:14:32 +01:00
parent 7cc85e8162
commit 8f746f9dde

View File

@ -56,4 +56,24 @@ exports.findParseTreeNode = function(nodeArray,search) {
return undefined;
};
/*
Helper to get the text of a parse tree node or array of nodes
*/
exports.getParseTreeText = function getParseTreeText(tree) {
var output = [];
if($tw.utils.isArray(tree)) {
$tw.utils.each(tree,function(node) {
output.push(getParseTreeText(node));
});
} else {
if(tree.type === "text") {
output.push(tree.text);
}
if(tree.children) {
return getParseTreeText(tree.children);
}
}
return output.join("");
};
})();