1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00
TiddlyWiki5/core/modules/parsers/wikiparser/rules/transcludeblock.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2012-12-15 17:35:35 +00:00
/*\
title: $:/core/modules/parsers/wikiparser/rules/transcludeblock.js
2012-12-15 17:35:35 +00:00
type: application/javascript
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";
exports.name = "transcludeblock";
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
};
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
var targetTitle = $tw.utils.trim(this.match[1]),
2012-12-15 17:35:35 +00:00
tooltip = this.match[2],
template = $tw.utils.trim(this.match[3]),
2012-12-23 10:36:55 +00:00
style = this.match[4],
classes = this.match[5];
2012-12-15 17:35:35 +00:00
// Return the transclude widget
var node = {
type: "element",
tag: "$transclude",
2012-12-15 17:35:35 +00:00
attributes: {
target: {type: "string", value: targetTitle}
},
isBlock: true
2012-12-15 17:35:35 +00:00
};
if(tooltip) {
node.attributes.tooltip = {type: "string", value: tooltip};
}
2012-12-23 10:36:55 +00:00
if(template) {
node.attributes.template = {type: "string", value: template};
}
2012-12-15 17:35:35 +00:00
if(style) {
node.attributes.style = {type: "string", value: style};
}
if(classes) {
node.attributes["class"] = {type: "string", value: classes.split(".").join(" ")};
2012-12-15 17:35:35 +00:00
}
return [node];
};
})();