1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Add template syntax for transclusion

This commit is contained in:
Jeremy Ruston 2012-12-23 10:36:55 +00:00
parent 8ef3e59416
commit 05ccb85759
2 changed files with 18 additions and 6 deletions

View File

@ -8,6 +8,8 @@ Wiki text rule for block-level transclusion. For example:
```
{{MyTiddler}}
{{MyTiddler|tooltip}}
{{MyTiddler||TemplateTitle}}
{{MyTiddler|tooltip||TemplateTitle}}
{{MyTiddler}width:40;height:50;}.class.class
```
@ -24,7 +26,7 @@ exports.types = {block: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?(?:\r?\n|$)/mg;
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\|\{\}]+))?(?:\|\|([^\|\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?(?:\r?\n|$)/mg;
};
exports.parse = function() {
@ -33,8 +35,9 @@ exports.parse = function() {
// Get the match details
var targetTitle = this.match[1],
tooltip = this.match[2],
style = this.match[3],
classes = this.match[4];
template = this.match[3],
style = this.match[4],
classes = this.match[5];
// Return the transclude widget
var node = {
type: "widget",
@ -47,6 +50,9 @@ exports.parse = function() {
if(tooltip) {
node.attributes.tooltip = {type: "string", value: tooltip};
}
if(template) {
node.attributes.template = {type: "string", value: template};
}
if(style) {
node.attributes.style = {type: "string", value: style};
}

View File

@ -8,6 +8,8 @@ Wiki text rule for inline-level transclusion. For example:
```
{{MyTiddler}}
{{MyTiddler|tooltip}}
{{MyTiddler||TemplateTitle}}
{{MyTiddler|tooltip||TemplateTitle}}
{{MyTiddler}width:40;height:50;}.class.class
```
@ -24,7 +26,7 @@ exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?/mg;
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\|\{\}]+))?(?:\|\|([^\|\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?/mg;
};
exports.parse = function() {
@ -33,8 +35,9 @@ exports.parse = function() {
// Get the match details
var targetTitle = this.match[1],
tooltip = this.match[2],
style = this.match[3],
classes = this.match[4];
template = this.match[3],
style = this.match[4],
classes = this.match[5];
// Return the transclude widget
var node = {
type: "widget",
@ -46,6 +49,9 @@ exports.parse = function() {
if(tooltip) {
node.attributes.tooltip = {type: "string", value: tooltip};
}
if(template) {
node.attributes.template = {type: "string", value: template};
}
if(style) {
node.attributes.style = {type: "string", value: style};
}