mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Update transclusion wikitext syntax to allow a template without a target tiddler
This allows us to transclude a tiddler without changing the current tiddler with `{{||MyTiddler}}`.
This commit is contained in:
parent
cdf3e101a8
commit
bdbbf94326
@ -23,19 +23,17 @@ exports.types = {block: true};
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|\|([^\|\{\}]+))?\}\}(?:\r?\n|$)/mg;
|
||||
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}(?:\r?\n|$)/mg;
|
||||
};
|
||||
|
||||
exports.parse = function() {
|
||||
// Move past the match
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Move past the match
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Get the match details
|
||||
var textRef = $tw.utils.trim(this.match[1]),
|
||||
tr = $tw.utils.parseTextReference(textRef),
|
||||
targetTitle = tr.title,
|
||||
targetField = tr.field,
|
||||
targetIndex = tr.index,
|
||||
template = $tw.utils.trim(this.match[2]);
|
||||
var template = $tw.utils.trim(this.match[2]),
|
||||
textRef = $tw.utils.trim(this.match[1]);
|
||||
// Prepare the transclude widget
|
||||
var transcludeNode = {
|
||||
type: "element",
|
||||
@ -43,27 +41,43 @@ exports.parse = function() {
|
||||
attributes: {},
|
||||
isBlock: true
|
||||
};
|
||||
var tiddlerNode = {
|
||||
type: "element",
|
||||
tag: "$tiddler",
|
||||
attributes: {
|
||||
tiddler: {type: "string", value: targetTitle}
|
||||
},
|
||||
isBlock: true,
|
||||
children: [transcludeNode]
|
||||
};
|
||||
// Prepare the tiddler widget
|
||||
if(textRef) {
|
||||
var tr = $tw.utils.parseTextReference(textRef),
|
||||
targetTitle = tr.title,
|
||||
targetField = tr.field,
|
||||
targetIndex = tr.index,
|
||||
tiddlerNode = {
|
||||
type: "element",
|
||||
tag: "$tiddler",
|
||||
attributes: {
|
||||
tiddler: {type: "string", value: targetTitle}
|
||||
},
|
||||
isBlock: true,
|
||||
children: [transcludeNode]
|
||||
};
|
||||
}
|
||||
if(template) {
|
||||
transcludeNode.attributes.tiddler = {type: "string", value: template};
|
||||
} else {
|
||||
transcludeNode.attributes.tiddler = {type: "string", value: targetTitle};
|
||||
if(targetField) {
|
||||
transcludeNode.attributes.field = {type: "string", value: targetField};
|
||||
if(textRef) {
|
||||
return [tiddlerNode];
|
||||
} else {
|
||||
return [transcludeNode];
|
||||
}
|
||||
if(targetIndex) {
|
||||
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
||||
} else {
|
||||
if(textRef) {
|
||||
transcludeNode.attributes.tiddler = {type: "string", value: targetTitle};
|
||||
if(targetField) {
|
||||
transcludeNode.attributes.field = {type: "string", value: targetField};
|
||||
}
|
||||
if(targetIndex) {
|
||||
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
||||
}
|
||||
return [tiddlerNode];
|
||||
} else {
|
||||
return [transcludeNode];
|
||||
}
|
||||
}
|
||||
return [tiddlerNode];
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -23,45 +23,57 @@ exports.types = {inline: true};
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|\|([^\|\{\}]+))?\}\}/mg;
|
||||
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}/mg;
|
||||
};
|
||||
|
||||
exports.parse = function() {
|
||||
// Move past the match
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
// Get the match details
|
||||
var textRef = $tw.utils.trim(this.match[1]),
|
||||
tr = $tw.utils.parseTextReference(textRef),
|
||||
targetTitle = tr.title,
|
||||
targetField = tr.field,
|
||||
targetIndex = tr.index,
|
||||
template = $tw.utils.trim(this.match[2]);
|
||||
var template = $tw.utils.trim(this.match[2]),
|
||||
textRef = $tw.utils.trim(this.match[1]);
|
||||
// Prepare the transclude widget
|
||||
var transcludeNode = {
|
||||
type: "element",
|
||||
tag: "$transclude",
|
||||
attributes: {}
|
||||
};
|
||||
var tiddlerNode = {
|
||||
type: "element",
|
||||
tag: "$tiddler",
|
||||
attributes: {
|
||||
tiddler: {type: "string", value: targetTitle}
|
||||
},
|
||||
children: [transcludeNode]
|
||||
};
|
||||
// Prepare the tiddler widget
|
||||
if(textRef) {
|
||||
var tr = $tw.utils.parseTextReference(textRef),
|
||||
targetTitle = tr.title,
|
||||
targetField = tr.field,
|
||||
targetIndex = tr.index,
|
||||
tiddlerNode = {
|
||||
type: "element",
|
||||
tag: "$tiddler",
|
||||
attributes: {
|
||||
tiddler: {type: "string", value: targetTitle}
|
||||
},
|
||||
children: [transcludeNode]
|
||||
};
|
||||
}
|
||||
if(template) {
|
||||
transcludeNode.attributes.tiddler = {type: "string", value: template};
|
||||
} else {
|
||||
transcludeNode.attributes.tiddler = {type: "string", value: targetTitle};
|
||||
if(targetField) {
|
||||
transcludeNode.attributes.field = {type: "string", value: targetField};
|
||||
if(textRef) {
|
||||
return [tiddlerNode];
|
||||
} else {
|
||||
return [transcludeNode];
|
||||
}
|
||||
if(targetIndex) {
|
||||
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
||||
} else {
|
||||
if(textRef) {
|
||||
transcludeNode.attributes.tiddler = {type: "string", value: targetTitle};
|
||||
if(targetField) {
|
||||
transcludeNode.attributes.field = {type: "string", value: targetField};
|
||||
}
|
||||
if(targetIndex) {
|
||||
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
||||
}
|
||||
return [tiddlerNode];
|
||||
} else {
|
||||
return [transcludeNode];
|
||||
}
|
||||
}
|
||||
return [tiddlerNode];
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -1,5 +1,5 @@
|
||||
created: 20140107114355828
|
||||
modified: 20140107114636001
|
||||
modified: 20140317213147507
|
||||
tags: concepts
|
||||
title: TemplateTiddlers
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -37,4 +37,4 @@ The TiddlerWidget is used to change the current tiddler. Consider a tiddler "C"
|
||||
|
||||
It is still transcluding tiddler "A", but now it is also setting the current tiddler to "A". The result is therefore that the field "myfield" for tiddler "A" is displayed.
|
||||
|
||||
The shorthand syntax for transcluding actually generates both a TiddlerWidget and a TranscludeWidget.
|
||||
The shorthand syntax for [[Transclusion in WikiText]] actually generates both a TiddlerWidget and a TranscludeWidget.
|
||||
|
@ -1,5 +1,5 @@
|
||||
created: 20131205160146648
|
||||
modified: 20140107114340951
|
||||
modified: 20140317214256948
|
||||
tags: wikitext
|
||||
title: Transclusion in WikiText
|
||||
type: text/vnd.tiddlywiki
|
||||
@ -8,6 +8,14 @@ You can incorporate the content of one tiddler within another using the transclu
|
||||
|
||||
* `{{MyTiddler}}` transcludes a single tiddler
|
||||
* `{{MyTiddler||TemplateTitle}}` displays the tiddler through a specified [[TemplateTiddler|TemplateTiddlers]]
|
||||
* `{{||TemplateTitle}}` displays the specified template tiddler without altering the [[current tiddler|WidgetVariable: currentTiddler]]
|
||||
|
||||
You can also use a TextReference instead of a tiddler title:
|
||||
|
||||
* `{{MyTiddler!!field}}` transcludes a specified field of a tiddler
|
||||
* `{{!!field}}` transcludes a specified field of the current tiddler
|
||||
* `{{MyTiddler##index}}` transcludes a specified indexed property of a [[DataTiddler|DataTiddlers]]
|
||||
* `{{##index}}` transcludes a specified indexed property of the current [[DataTiddler|DataTiddlers]]
|
||||
|
||||
A similar syntax can be used to transclude a list of tiddlers matching a specified [[TiddlerFilter|TiddlerFilters]]:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user