Resolve another inefficiency

The transclusion target was sometimes being parsed twice when transcluding as text/plain

Associated test results are also made more consistent
This commit is contained in:
Jeremy Ruston 2023-07-29 16:31:10 +01:00
parent fa5bae0150
commit 99232c3c82
2 changed files with 11 additions and 5 deletions

View File

@ -69,12 +69,17 @@ TranscludeWidget.prototype.execute = function() {
parseTreeNodes = [{type: "text", text: this.sourceText}];
break;
default:
// text/plain is the plain text result of wikifying the text
target = this.getTransclusionTarget();
// "text/plain" is the plain text result of wikifying the text
target = this.getTransclusionTargetIncludingParseTreeNodes();
this.sourceText = target.text;
this.parserType = target.type;
var plainText = this.wiki.renderText("text/plain",this.parserType,this.sourceText,{parentWidget: this});
parseTreeNodes = [{type: "text", text: plainText}];
var widgetNode = this.wiki.makeWidget(target.parser,{
parentWidget: this,
document: $tw.fakeDocument
});
var container = $tw.fakeDocument.createElement("div");
widgetNode.render(container,null);
parseTreeNodes = [{type: "text", text: container.textContent}];
break;
}
// Set the legacy transclusion context variables only if we're not transcluding a variable
@ -309,6 +314,7 @@ TranscludeWidget.prototype.getTransclusionTargetIncludingParseTreeNodes = functi
}
// Return the parse tree
return {
parser: parser,
parseTreeNodes: parser ? parser.tree : (this.slotFillParseTrees["ts-missing"] || []),
parseAsInline: parseAsInline,
text: parser && parser.source,

View File

@ -33,4 +33,4 @@ $param$ with a ''buffalo''
+
title: ExpectedResult
<p>Going to lunch with a ''buffalo''</p><p>Going to breakfastwith a<strong>buffalo</strong></p><p>Going to dinner with a <strong>buffalo</strong></p>Going to lunch with a buffalo with a buffaloGoing to dinner with a buffalo
<p>Going to lunch with a ''buffalo''</p><p>Going to breakfastwith a<strong>buffalo</strong></p><p>Going to dinner with a <strong>buffalo</strong></p>Going to lunch with a ''buffalo''Going to breakfastwith abuffaloGoing to dinner with a buffalo