2012-12-20 17:03:41 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/parsers/wikiparser/rules/macrocallblock.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: wikirule
|
|
|
|
|
|
|
|
Wiki rule for block macro calls
|
|
|
|
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-20 17:03:41 +00:00
|
|
|
<<name value value2>>
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-20 17:03:41 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
2012-12-26 19:32:54 +00:00
|
|
|
exports.name = "macrocallblock";
|
2012-12-20 17:03:41 +00:00
|
|
|
exports.types = {block: true};
|
|
|
|
|
|
|
|
exports.init = function(parser) {
|
|
|
|
this.parser = parser;
|
2021-01-29 13:26:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.findNextMatch = function(startPos) {
|
|
|
|
var nextStart = startPos;
|
|
|
|
// Try parsing at all possible macrocall openers until we match
|
|
|
|
while((nextStart = this.parser.source.indexOf("<<",nextStart)) >= 0) {
|
2022-05-08 14:59:20 +00:00
|
|
|
var nextCall = $tw.utils.parseMacroInvocationAsTransclusion(this.parser.source,nextStart);
|
2021-01-29 13:26:31 +00:00
|
|
|
if(nextCall) {
|
|
|
|
var c = this.parser.source.charAt(nextCall.end);
|
|
|
|
// Ensure EOL after parsed macro
|
|
|
|
// If we didn't need to support IE, we'd just use /(?:\r?\n|$)/ym
|
|
|
|
if ((c === "") || (c === "\n") || ((c === "\r") && this.parser.source.charAt(nextCall.end+1) === "\n")) {
|
|
|
|
this.nextCall = nextCall;
|
|
|
|
return nextStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nextStart += 2;
|
|
|
|
}
|
|
|
|
return undefined;
|
2012-12-20 17:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Parse the most recent match
|
|
|
|
*/
|
|
|
|
exports.parse = function() {
|
2021-01-29 13:26:31 +00:00
|
|
|
var call = this.nextCall;
|
|
|
|
call.isBlock = true;
|
|
|
|
this.nextCall = null;
|
|
|
|
this.parser.pos = call.end;
|
|
|
|
return [call];
|
2012-12-20 17:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|