mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-18 02:09:43 +00:00
006ae6e759
The objective is to add a $depth attribute so that it is possible to reach up to retrieve the parameters of ancestor transclusions. However, doing so requires changing the encoding of parameter names so that it is not possible for a user parameter to clash with an attribute like $depth. So now we have to double up dollars on any attribute names seen by the parameters widget, just like with the transclude widget itself.
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
/*\
|
|
title: $:/core/modules/parsers/wikiparser/rules/parameters.js
|
|
type: application/javascript
|
|
module-type: wikirule
|
|
|
|
Wiki pragma rule for parameter definitions
|
|
|
|
```
|
|
\parameters(param:defaultvalue,param2:defaultvalue)
|
|
definition text
|
|
```
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
exports.name = "parameters";
|
|
exports.types = {pragma: true};
|
|
|
|
/*
|
|
Instantiate parse rule
|
|
*/
|
|
exports.init = function(parser) {
|
|
this.parser = parser;
|
|
// Regexp to match
|
|
this.matchRegExp = /^\\parameters\s*\(([^)]*)\)\s*\r?\n/mg;
|
|
};
|
|
|
|
/*
|
|
Parse the most recent match
|
|
*/
|
|
exports.parse = function() {
|
|
// Move past the macro name and parameters
|
|
this.parser.pos = this.matchRegExp.lastIndex;
|
|
// Parse the parameters
|
|
var params = $tw.utils.parseParameterDefinition(this.match[1]);
|
|
var attributes = Object.create(null),
|
|
orderedAttributes = [];
|
|
$tw.utils.each(params,function(param) {
|
|
var name = param.name;
|
|
// Parameter names starting with dollar must be escaped to double dollars for the parameters widget
|
|
if(name.charAt(0) === "$") {
|
|
name = "$" + name;
|
|
}
|
|
var attribute = {name: name, type: "string", value: param["default"] || ""};
|
|
attributes[name] = attribute;
|
|
orderedAttributes.push(attribute);
|
|
});
|
|
// Save the macro definition
|
|
return [{
|
|
type: "parameters",
|
|
attributes: attributes,
|
|
orderedAttributes: orderedAttributes
|
|
}];
|
|
};
|
|
|
|
})();
|