mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 09:50:27 +00:00
Add parse tree utility for collecting text
This commit is contained in:
parent
7cc85e8162
commit
8f746f9dde
@ -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("");
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user