2012-12-15 17:35:35 +00:00
|
|
|
/*\
|
2012-12-20 16:41:06 +00:00
|
|
|
title: $:/core/modules/parsers/wikiparser/rules/transcludeblock.js
|
2012-12-15 17:35:35 +00:00
|
|
|
type: application/javascript
|
2012-12-20 16:02:03 +00:00
|
|
|
module-type: wikirule
|
2012-12-15 17:35:35 +00:00
|
|
|
|
|
|
|
Wiki text rule for block-level transclusion. For example:
|
|
|
|
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-15 17:35:35 +00:00
|
|
|
{{MyTiddler}}
|
|
|
|
{{MyTiddler|tooltip}}
|
2012-12-23 10:36:55 +00:00
|
|
|
{{MyTiddler||TemplateTitle}}
|
|
|
|
{{MyTiddler|tooltip||TemplateTitle}}
|
2012-12-15 17:35:35 +00:00
|
|
|
{{MyTiddler}width:40;height:50;}.class.class
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-15 17:35:35 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-12-26 19:32:54 +00:00
|
|
|
exports.name = "transcludeblock";
|
2012-12-20 16:02:03 +00:00
|
|
|
exports.types = {block: true};
|
2012-12-15 17:35:35 +00:00
|
|
|
|
|
|
|
exports.init = function(parser) {
|
|
|
|
this.parser = parser;
|
|
|
|
// Regexp to match
|
2012-12-23 10:36:55 +00:00
|
|
|
this.matchRegExp = /\{\{([^\{\}\|]+)(?:\|([^\|\{\}]+))?(?:\|\|([^\|\{\}]+))?\}([^\}]*)\}(?:\.(\S+))?(?:\r?\n|$)/mg;
|
2012-12-15 17:35:35 +00:00
|
|
|
};
|
|
|
|
|
2012-12-20 15:07:38 +00:00
|
|
|
exports.parse = function() {
|
2012-12-15 17:35:35 +00:00
|
|
|
// Move past the match
|
|
|
|
this.parser.pos = this.matchRegExp.lastIndex;
|
|
|
|
// Get the match details
|
2013-01-15 17:50:47 +00:00
|
|
|
var textRef = $tw.utils.trim(this.match[1]),
|
|
|
|
tr = $tw.utils.parseTextReference(textRef),
|
|
|
|
targetTitle = tr.title,
|
|
|
|
targetField = tr.field,
|
|
|
|
targetIndex = tr.index,
|
2012-12-15 17:35:35 +00:00
|
|
|
tooltip = this.match[2],
|
2012-12-26 19:32:54 +00:00
|
|
|
template = $tw.utils.trim(this.match[3]),
|
2012-12-23 10:36:55 +00:00
|
|
|
style = this.match[4],
|
|
|
|
classes = this.match[5];
|
2013-08-24 15:45:45 +00:00
|
|
|
// Prepare the transclude widget
|
|
|
|
var transcludeNode = {
|
|
|
|
type: "element",
|
|
|
|
tag: "$transclude",
|
|
|
|
attributes: {
|
2013-10-30 13:36:44 +00:00
|
|
|
tiddler: {type: "string", value: template || targetTitle}
|
2013-08-24 15:45:45 +00:00
|
|
|
},
|
|
|
|
isBlock: true
|
|
|
|
};
|
|
|
|
var tiddlerNode = {
|
2013-01-03 16:27:55 +00:00
|
|
|
type: "element",
|
2013-08-24 15:45:45 +00:00
|
|
|
tag: "$tiddler",
|
2012-12-15 17:35:35 +00:00
|
|
|
attributes: {
|
2013-10-30 13:36:44 +00:00
|
|
|
tiddler: {type: "string", value: targetTitle}
|
2012-12-20 15:07:38 +00:00
|
|
|
},
|
2013-08-24 15:45:45 +00:00
|
|
|
isBlock: true,
|
|
|
|
children: [transcludeNode]
|
2012-12-15 17:35:35 +00:00
|
|
|
};
|
2013-01-15 17:50:47 +00:00
|
|
|
if(targetField) {
|
2013-08-24 15:45:45 +00:00
|
|
|
transcludeNode.attributes.field = {type: "string", value: targetField};
|
2013-01-15 17:50:47 +00:00
|
|
|
}
|
|
|
|
if(targetIndex) {
|
2013-08-24 15:45:45 +00:00
|
|
|
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
2013-01-15 17:50:47 +00:00
|
|
|
}
|
2012-12-15 17:35:35 +00:00
|
|
|
if(tooltip) {
|
2013-08-24 15:45:45 +00:00
|
|
|
transcludeNode.attributes.tooltip = {type: "string", value: tooltip};
|
2012-12-23 10:36:55 +00:00
|
|
|
}
|
2012-12-15 17:35:35 +00:00
|
|
|
if(style) {
|
2013-08-24 15:45:45 +00:00
|
|
|
transcludeNode.attributes.style = {type: "string", value: style};
|
2012-12-15 17:35:35 +00:00
|
|
|
}
|
2012-12-20 15:07:38 +00:00
|
|
|
if(classes) {
|
2013-08-24 15:45:45 +00:00
|
|
|
transcludeNode.attributes["class"] = {type: "string", value: classes.split(".").join(" ")};
|
2012-12-15 17:35:35 +00:00
|
|
|
}
|
2013-08-24 15:45:45 +00:00
|
|
|
return [tiddlerNode];
|
2012-12-15 17:35:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|