1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-29 12:59:56 +00:00

Clean up transclude widget

1. Update comments
2. Refactor use of parseTreeNodes so that they are not referenced unnecessarily
3. getTransclusionTarget doesn't need to return the parser object
This commit is contained in:
Jeremy Ruston 2023-07-16 14:04:09 +01:00
parent 3bd8c5d50d
commit b54a88ce83

View File

@ -41,16 +41,17 @@ TranscludeWidget.prototype.execute = function() {
this.collectAttributes(); this.collectAttributes();
this.collectStringParameters(); this.collectStringParameters();
this.collectSlotFillParameters(); this.collectSlotFillParameters();
// Get the parse tree nodes that we are transcluding // Get the target text and parse tree nodes that we are transcluding
var target = this.getTransclusionTarget(), var target = this.getTransclusionTarget(),
parseTreeNodes = target.parseTreeNodes; parseTreeNodes;
this.sourceText = target.text; this.sourceText = target.text;
this.parserType = target.type; this.parserType = target.type;
this.parseAsInline = target.parseAsInline; this.parseAsInline = target.parseAsInline;
// Process the transclusion according to the output type // Process the transclusion according to the output type
switch(this.transcludeOutput || "text/html") { switch(this.transcludeOutput || "text/html") {
case "text/html": case "text/html":
// No further processing required // Return the parse tree nodes
parseTreeNodes = target.parseTreeNodes;
break; break;
case "text/raw": case "text/raw":
// Just return the raw text // Just return the raw text
@ -158,7 +159,7 @@ TranscludeWidget.prototype.collectSlotFillParameters = function() {
}; };
/* /*
Get transcluded parse tree nodes as an object {parser:,text:,type:} Get transcluded parse tree nodes as an object {text:,type:,parseTreeNodes:,parseAsInline:}
*/ */
TranscludeWidget.prototype.getTransclusionTarget = function() { TranscludeWidget.prototype.getTransclusionTarget = function() {
var self = this; var self = this;
@ -270,7 +271,6 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
// Return the parse tree // Return the parse tree
if(parser) { if(parser) {
return { return {
parser: parser,
parseTreeNodes: parser.tree, parseTreeNodes: parser.tree,
parseAsInline: parseAsInline, parseAsInline: parseAsInline,
text: parser.source, text: parser.source,
@ -279,7 +279,6 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
} else { } else {
// If there's no parse tree then return the missing slot value // If there's no parse tree then return the missing slot value
return { return {
parser: null,
parseTreeNodes: (this.slotFillParseTrees["ts-missing"] || []), parseTreeNodes: (this.slotFillParseTrees["ts-missing"] || []),
parseAsInline: parseAsInline, parseAsInline: parseAsInline,
text: null, text: null,