From 967657c6dd60f6c4e55fb3dad13fd9e986d3409c Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Mon, 17 Jun 2024 17:45:16 +0800 Subject: [PATCH] fix: only fallback to title when {{!!xxx}}, not when input is empty --- core/modules/wiki.js | 15 ++++++++++----- .../test/tiddlers/tests/test-backtranscludes.js | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index e1821e108..d57fd6098 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -564,18 +564,23 @@ exports.extractTranscludes = function(parseTreeRoot, title) { var value; // if it is Transclusion with Templates like `{{Index||$:/core/ui/TagTemplate}}`, the `$tiddler` will point to the template. We need to find the actual target tiddler from parent node if(parentNode && parentNode.type === "tiddler" && parentNode.attributes.tiddler && parentNode.attributes.tiddler.type === "string") { - value = parentNode.attributes.tiddler.value; + // Empty value (like `{{!!field}}`) means self-referential transclusion. + value = parentNode.attributes.tiddler.value || title; } else { value = parseTreeNode.attributes.$tiddler.value; } } else if(parseTreeNode.attributes.tiddler && parseTreeNode.attributes.tiddler.type === "string") { + // Old transclude widget usage value = parseTreeNode.attributes.tiddler.value; - } - if (!value) { + } else if(parseTreeNode.attributes.$field && parseTreeNode.attributes.$field.type === "string") { + // Empty value (like `<$transclude $field='created'/>`) means self-referential transclusion. + value = title; + } else if(parseTreeNode.attributes.field && parseTreeNode.attributes.field.type === "string") { + // Old usage with Empty value (like `<$transclude field='created'/>`) value = title; } - // Empty value (like `{{!!field}}`) means self-referential transclusion. Also deduplicate the result. - if(transcludes.indexOf(value) === -1) { + // Deduplicate the result. + if(value && transcludes.indexOf(value) === -1) { transcludes.push(value); } } diff --git a/editions/test/tiddlers/tests/test-backtranscludes.js b/editions/test/tiddlers/tests/test-backtranscludes.js index bae0e83ee..cd089df94 100644 --- a/editions/test/tiddlers/tests/test-backtranscludes.js +++ b/editions/test/tiddlers/tests/test-backtranscludes.js @@ -22,6 +22,9 @@ describe('Backtranscludes and transclude filter tests', function() { it('should have no backtranscludes', function() { expect(wiki.filterTiddlers('TestIncoming +[backtranscludes[]]').join(',')).toBe(''); }); + it('should have no transcludes', function() { + expect(wiki.filterTiddlers('TestIncoming +[transcludes[]]').join(',')).toBe(''); + }); }); describe('A tiddler added to the wiki with a transclude to it', function() { @@ -38,6 +41,9 @@ describe('Backtranscludes and transclude filter tests', function() { it('should have a backtransclude', function() { expect(wiki.filterTiddlers('TestIncoming +[backtranscludes[]]').join(',')).toBe('TestOutgoing'); }); + it('should have a transclude', function() { + expect(wiki.filterTiddlers('TestOutgoing +[transcludes[]]').join(',')).toBe('TestIncoming'); + }); }); describe('A tiddler transclude with template will still use the tiddler as result.', function() {