1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-31 03:14:49 +00:00

feat: support old <$transclude tiddler param

This commit is contained in:
lin onetwo 2024-06-12 22:07:00 +08:00
parent 78d1bd1570
commit a3bf9c0f1c
2 changed files with 14 additions and 9 deletions

View File

@ -559,13 +559,17 @@ exports.extractTranscludes = function(parseTreeRoot, title) {
checkParseTree = function(parseTree, parentNode) {
for(var t=0; t<parseTree.length; t++) {
var parseTreeNode = parseTree[t];
if(parseTreeNode.type === "transclude" && parseTreeNode.attributes.$tiddler && parseTreeNode.attributes.$tiddler.type === "string") {
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;
} else {
value = parseTreeNode.attributes.$tiddler.value;
if(parseTreeNode.type === "transclude") {
if(parseTreeNode.attributes.$tiddler && parseTreeNode.attributes.$tiddler.type === "string") {
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;
} else {
value = parseTreeNode.attributes.$tiddler.value;
}
} else if(parseTreeNode.attributes.tiddler && parseTreeNode.attributes.tiddler.type === "string") {
value = parseTreeNode.attributes.tiddler.value;
}
// ignore empty value (like `{{!!field}}`), and deduplicate
if(value && transcludes.indexOf(value) === -1 && value !== title) {

View File

@ -219,14 +219,15 @@ describe('Backtranscludes and transclude filter tests', function() {
wiki.addTiddler({
title: 'TestOutgoing',
text: "<$tiddler tiddler='TestIncoming'><$transclude $tiddler /></$tiddler>"});
text: "<$tiddler tiddler='TestIncoming'><$transclude $tiddler /></$tiddler>\n\n<$transclude tiddler='TiddlyWiki Pre-release'/>"});
it('should have a transclude', function() {
expect(wiki.filterTiddlers('TestOutgoing +[transcludes[]]').join(',')).toBe('TestIncoming');
expect(wiki.filterTiddlers('TestOutgoing +[transcludes[]]').join(',')).toBe('TestIncoming,TiddlyWiki Pre-release');
});
it('should have a back transclude', function() {
expect(wiki.filterTiddlers('TestIncoming +[backtranscludes[]]').join(',')).toBe('TestOutgoing');
expect(wiki.filterTiddlers('[[TiddlyWiki Pre-release]] +[backtranscludes[]]').join(',')).toBe('TestOutgoing');
});
});
});