1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-28 20:12:41 +00:00
TiddlyWiki5/core/modules/parsers/newwikitextparser/rules/transclude.js
Jeremy Ruston 0d928c05a5 Added new transclude wikitext rule and macro
Which allows us to get rid of the tags macro
2012-06-19 08:57:29 +01:00

60 lines
1.3 KiB
JavaScript

/*\
title: $:/core/modules/parsers/newwikitextparser/rules/transclude.js
type: application/javascript
module-type: wikitextrule
Wiki text rule for transclusion. For example:
{{{
((MyTiddler))
((MyTiddler)(MyTemplate))
((MyTiddler)Template <<view text>>)
(((My filter expression)))
(((My filter expression))(MyTemplate))
(((My filter expression))Template <<view text>>)
}}}
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "transclude";
exports.runParser = true;
exports.blockParser = true;
exports.regExpString = "\\(\\((?:(?:[^\\(\\)]+)|(?:\\([^\\(\\)]+\\)))\\)(?:\\([^\\)]+\\)|(?:[^\\)]+))?\\)";
exports.parse = function(match,isBlock) {
var regExp = /\(\((?:([^\(\)]+)|(?:\(([^\(\)]+)\)))\)(?:\(([^\)]+)\)|([^\)]+))?\)((?:\r?\n)?)/mg;
regExp.lastIndex = this.pos;
match = regExp.exec(this.source);
if(match && match.index === this.pos) {
this.pos = match.index + match[0].length;
var params = {};
// Check if it is a single tiddler
if(match[1]) {
params.title = match[1];
} else {
// Else it is a filter
params.filter = match[2];
}
if(match[3]) {
params.templateTitle = match[3];
}
if(match[4]) {
params.templateText = match[4];
}
return [$tw.Tree.Macro("transclude",{
srcParams: params,
wiki: this.wiki
})];
}
return [];
};
})();