Skip to content

Commit

Permalink
feat: allow $tw.utils.getParseTreeText to render other rules' text
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Jun 12, 2024
1 parent 37338b1 commit 8a12498
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/modules/utils/parsetree.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ exports.findParseTreeNode = function(nodeArray,search) {
/*
Helper to get the text of a parse tree node or array of nodes
*/
exports.getParseTreeText = function getParseTreeText(tree) {
exports.getParseTreeText = function getParseTreeText(tree, tiddlerType) {
var output = [];
if($tw.utils.isArray(tree)) {
$tw.utils.each(tree,function(node) {
Expand All @@ -115,6 +115,14 @@ exports.getParseTreeText = function getParseTreeText(tree) {
} else {
if(tree.type === "text") {
output.push(tree.text);
} else {
var Parser = $tw.wiki.getParser(tiddlerType);
var Rule = Parser.prototype.blockRuleClasses[tree.type] ||
Parser.prototype.inlineRuleClasses[tree.type] ||
Parser.prototype.pragmaRuleClasses[tree.type];
if(Rule && Rule.prototype.getText) {
output.push(Rule.prototype.getText(tree));
}
}
if(tree.children) {
return getParseTreeText(tree.children);
Expand Down

0 comments on commit 8a12498

Please sign in to comment.