kopia lustrzana https://github.com/miklobit/TiddlyWiki5
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}}`.print-window-tiddler
rodzic
cdf3e101a8
commit
bdbbf94326
|
@ -23,19 +23,17 @@ exports.types = {block: true};
|
||||||
exports.init = function(parser) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match
|
// Regexp to match
|
||||||
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|\|([^\|\{\}]+))?\}\}(?:\r?\n|$)/mg;
|
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}(?:\r?\n|$)/mg;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parse = function() {
|
exports.parse = function() {
|
||||||
|
// Move past the match
|
||||||
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
// Move past the match
|
// Move past the match
|
||||||
this.parser.pos = this.matchRegExp.lastIndex;
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
// Get the match details
|
// Get the match details
|
||||||
var textRef = $tw.utils.trim(this.match[1]),
|
var template = $tw.utils.trim(this.match[2]),
|
||||||
tr = $tw.utils.parseTextReference(textRef),
|
textRef = $tw.utils.trim(this.match[1]);
|
||||||
targetTitle = tr.title,
|
|
||||||
targetField = tr.field,
|
|
||||||
targetIndex = tr.index,
|
|
||||||
template = $tw.utils.trim(this.match[2]);
|
|
||||||
// Prepare the transclude widget
|
// Prepare the transclude widget
|
||||||
var transcludeNode = {
|
var transcludeNode = {
|
||||||
type: "element",
|
type: "element",
|
||||||
|
@ -43,27 +41,43 @@ exports.parse = function() {
|
||||||
attributes: {},
|
attributes: {},
|
||||||
isBlock: true
|
isBlock: true
|
||||||
};
|
};
|
||||||
var tiddlerNode = {
|
// Prepare the tiddler widget
|
||||||
type: "element",
|
if(textRef) {
|
||||||
tag: "$tiddler",
|
var tr = $tw.utils.parseTextReference(textRef),
|
||||||
attributes: {
|
targetTitle = tr.title,
|
||||||
tiddler: {type: "string", value: targetTitle}
|
targetField = tr.field,
|
||||||
},
|
targetIndex = tr.index,
|
||||||
isBlock: true,
|
tiddlerNode = {
|
||||||
children: [transcludeNode]
|
type: "element",
|
||||||
};
|
tag: "$tiddler",
|
||||||
|
attributes: {
|
||||||
|
tiddler: {type: "string", value: targetTitle}
|
||||||
|
},
|
||||||
|
isBlock: true,
|
||||||
|
children: [transcludeNode]
|
||||||
|
};
|
||||||
|
}
|
||||||
if(template) {
|
if(template) {
|
||||||
transcludeNode.attributes.tiddler = {type: "string", value: template};
|
transcludeNode.attributes.tiddler = {type: "string", value: template};
|
||||||
} else {
|
if(textRef) {
|
||||||
transcludeNode.attributes.tiddler = {type: "string", value: targetTitle};
|
return [tiddlerNode];
|
||||||
if(targetField) {
|
} else {
|
||||||
transcludeNode.attributes.field = {type: "string", value: targetField};
|
return [transcludeNode];
|
||||||
}
|
}
|
||||||
if(targetIndex) {
|
} else {
|
||||||
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
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) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match
|
// Regexp to match
|
||||||
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|\|([^\|\{\}]+))?\}\}/mg;
|
this.matchRegExp = /\{\{([^\{\}\|]*)(?:\|\|([^\|\{\}]+))?\}\}/mg;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.parse = function() {
|
exports.parse = function() {
|
||||||
// Move past the match
|
// Move past the match
|
||||||
this.parser.pos = this.matchRegExp.lastIndex;
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
// Get the match details
|
// Get the match details
|
||||||
var textRef = $tw.utils.trim(this.match[1]),
|
var template = $tw.utils.trim(this.match[2]),
|
||||||
tr = $tw.utils.parseTextReference(textRef),
|
textRef = $tw.utils.trim(this.match[1]);
|
||||||
targetTitle = tr.title,
|
|
||||||
targetField = tr.field,
|
|
||||||
targetIndex = tr.index,
|
|
||||||
template = $tw.utils.trim(this.match[2]);
|
|
||||||
// Prepare the transclude widget
|
// Prepare the transclude widget
|
||||||
var transcludeNode = {
|
var transcludeNode = {
|
||||||
type: "element",
|
type: "element",
|
||||||
tag: "$transclude",
|
tag: "$transclude",
|
||||||
attributes: {}
|
attributes: {}
|
||||||
};
|
};
|
||||||
var tiddlerNode = {
|
// Prepare the tiddler widget
|
||||||
type: "element",
|
if(textRef) {
|
||||||
tag: "$tiddler",
|
var tr = $tw.utils.parseTextReference(textRef),
|
||||||
attributes: {
|
targetTitle = tr.title,
|
||||||
tiddler: {type: "string", value: targetTitle}
|
targetField = tr.field,
|
||||||
},
|
targetIndex = tr.index,
|
||||||
children: [transcludeNode]
|
tiddlerNode = {
|
||||||
};
|
type: "element",
|
||||||
|
tag: "$tiddler",
|
||||||
|
attributes: {
|
||||||
|
tiddler: {type: "string", value: targetTitle}
|
||||||
|
},
|
||||||
|
children: [transcludeNode]
|
||||||
|
};
|
||||||
|
}
|
||||||
if(template) {
|
if(template) {
|
||||||
transcludeNode.attributes.tiddler = {type: "string", value: template};
|
transcludeNode.attributes.tiddler = {type: "string", value: template};
|
||||||
} else {
|
if(textRef) {
|
||||||
transcludeNode.attributes.tiddler = {type: "string", value: targetTitle};
|
return [tiddlerNode];
|
||||||
if(targetField) {
|
} else {
|
||||||
transcludeNode.attributes.field = {type: "string", value: targetField};
|
return [transcludeNode];
|
||||||
}
|
}
|
||||||
if(targetIndex) {
|
} else {
|
||||||
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
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
|
created: 20140107114355828
|
||||||
modified: 20140107114636001
|
modified: 20140317213147507
|
||||||
tags: concepts
|
tags: concepts
|
||||||
title: TemplateTiddlers
|
title: TemplateTiddlers
|
||||||
type: text/vnd.tiddlywiki
|
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.
|
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
|
created: 20131205160146648
|
||||||
modified: 20140107114340951
|
modified: 20140317214256948
|
||||||
tags: wikitext
|
tags: wikitext
|
||||||
title: Transclusion in WikiText
|
title: Transclusion in WikiText
|
||||||
type: text/vnd.tiddlywiki
|
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}}` transcludes a single tiddler
|
||||||
* `{{MyTiddler||TemplateTitle}}` displays the tiddler through a specified [[TemplateTiddler|TemplateTiddlers]]
|
* `{{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]]:
|
A similar syntax can be used to transclude a list of tiddlers matching a specified [[TiddlerFilter|TiddlerFilters]]:
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue