mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-05-01 05:06:57 +00:00
Now that transclusion doesn't generate any intrinsic elements we don't have an element to attach the tooltip, classes and styles to.
65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
/*\
|
|
title: $:/core/modules/parsers/wikiparser/rules/transcludeinline.js
|
|
type: application/javascript
|
|
module-type: wikirule
|
|
|
|
Wiki text rule for inline-level transclusion. For example:
|
|
|
|
```
|
|
{{MyTiddler}}
|
|
{{MyTiddler||TemplateTitle}}
|
|
```
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
exports.name = "transcludeinline";
|
|
exports.types = {inline: true};
|
|
|
|
exports.init = function(parser) {
|
|
this.parser = parser;
|
|
// Regexp to match
|
|
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]);
|
|
// Prepare the transclude widget
|
|
var transcludeNode = {
|
|
type: "element",
|
|
tag: "$transclude",
|
|
attributes: {
|
|
tiddler: {type: "string", value: template || targetTitle}
|
|
}
|
|
};
|
|
var tiddlerNode = {
|
|
type: "element",
|
|
tag: "$tiddler",
|
|
attributes: {
|
|
tiddler: {type: "string", value: targetTitle}
|
|
},
|
|
children: [transcludeNode]
|
|
};
|
|
if(targetField) {
|
|
transcludeNode.attributes.field = {type: "string", value: targetField};
|
|
}
|
|
if(targetIndex) {
|
|
transcludeNode.attributes.index = {type: "string", value: targetIndex};
|
|
}
|
|
return [tiddlerNode];
|
|
};
|
|
|
|
})();
|