1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-17 23:34:50 +00:00

Fix and test missing target handling

This commit is contained in:
jeremy@jermolene.com 2022-04-26 12:32:46 +01:00
parent 54b48876f7
commit 05b582a202
2 changed files with 56 additions and 4 deletions

View File

@ -47,22 +47,26 @@ UberTranscludeWidget.prototype.execute = function() {
this.transcludeIndex = this.getAttribute("$index");
this.transcludeMode = this.getAttribute("$mode");
this.recursionMarker = this.getAttribute("$recursionMarker","yes");
// Find the value widgets in our parse tree
// Find the value widgets in our child parse tree
this.slotValueParseTrees = Object.create(null);
this.slotValueParseTrees.missing = this.parseTreeNode.children;
var searchParseTreeNodes = function(nodes) {
var noValueWidgetsFound = true,
searchParseTreeNodes = function(nodes) {
$tw.utils.each(nodes,function(node) {
if(node.type === "value" && node.tag === "$value") {
if(node.attributes["$name"] && node.attributes["$name"].type === "string") {
var slotValueName = node.attributes["$name"].value;
self.slotValueParseTrees[slotValueName] = node.children;
}
noValueWidgetsFound = false;
} else {
searchParseTreeNodes(node.children);
}
});
};
searchParseTreeNodes(this.parseTreeNode.children);
if(noValueWidgetsFound) {
this.slotValueParseTrees["missing"] = this.parseTreeNode.children;
}
// Parse the text reference
var parseAsInline = !this.parseTreeNode.isBlock;
if(this.transcludeMode === "inline") {
@ -83,7 +87,7 @@ UberTranscludeWidget.prototype.execute = function() {
subTiddler: this.transcludeSubTiddler
});
}
var parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
var parseTreeNodes = parser ? parser.tree : (this.slotValueParseTrees["missing"] || []);
this.sourceText = parser ? parser.source : null;
this.parserType = parser? parser.type : null;
// Set context variables for recursion detection

View File

@ -0,0 +1,48 @@
title: Ubertransclude/MissingTarget
description: Transcluding a missing target
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$ubertransclude $tiddler='TiddlerOne' one='Ferret'>
<$parameters one='Ferret'>
Badger
<$text text=<<one>>/>
</$parameters>
</$ubertransclude>
<$ubertransclude $tiddler='TiddlerOne' one='Ferret'>
<$value $name="missing">
<$parameters one='Ferret'>
Badger
<$text text=<<one>>/>
</$parameters>
</$value>
</$ubertransclude>
<$ubertransclude $tiddler='MissingTiddler' one='Ferret'>
<$parameters one='Ferret'>
Badger
<$text text=<<one>>/>
</$parameters>
</$ubertransclude>
<$ubertransclude $tiddler='MissingTiddler' one='Ferret'>
<$value $name="missing">
<$parameters one='Ferret'>
Badger
<$text text=<<one>>/>
</$parameters>
</$value>
</$ubertransclude>
_
title: TiddlerOne
\whitespace trim
<$parameters one='Kangaroo'>
Piranha
<$text text=<<one>>/>
</$parameters>
_
title: ExpectedResult
<p>PiranhaFerretPiranhaFerretBadgerFerretBadgerFerret</p>