2022-05-02 08:15:45 +00:00
|
|
|
/*\
|
|
|
|
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
|
2022-05-27 17:37:42 +00:00
|
|
|
var params = $tw.utils.parseParameterDefinition(this.match[1]);
|
|
|
|
var attributes = Object.create(null),
|
|
|
|
orderedAttributes = [];
|
|
|
|
$tw.utils.each(params,function(param) {
|
|
|
|
var attribute = {name: param.name, type: "string", value: param["default"] || ""};
|
|
|
|
attributes[param.name] = attribute;
|
2022-05-02 08:15:45 +00:00
|
|
|
orderedAttributes.push(attribute);
|
2022-05-27 17:37:42 +00:00
|
|
|
});
|
2022-05-02 08:15:45 +00:00
|
|
|
// Save the macro definition
|
|
|
|
return [{
|
|
|
|
type: "parameters",
|
|
|
|
attributes: attributes,
|
|
|
|
orderedAttributes: orderedAttributes
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|