mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-19 10:49:43 +00:00
45355a7fcf
* wikirules now use better macrocall parser Before, wikirules would use a deficient macrocall parser which couldn't handle certain types of arguments. Now it uses the same one that the widget parser uses. Less code! * style changes and removing weird switch statement That switch statement made more sense in an earlier iteration. * comment improvements * oops, wikirule macrocalls could do ONE thing better * '=' wasn't allowed for widget macros, but why? Now they're allowed for both widget macros and macrocall macros.
50 lines
951 B
JavaScript
50 lines
951 B
JavaScript
/*\
|
|
title: $:/core/modules/parsers/wikiparser/rules/macrocallinline.js
|
|
type: application/javascript
|
|
module-type: wikirule
|
|
|
|
Wiki rule for macro calls
|
|
|
|
```
|
|
<<name value value2>>
|
|
```
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
exports.name = "macrocallinline";
|
|
exports.types = {inline: true};
|
|
|
|
exports.init = function(parser) {
|
|
this.parser = parser;
|
|
};
|
|
|
|
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) {
|
|
this.nextCall = $tw.utils.parseMacroInvocation(this.parser.source,nextStart);
|
|
if(this.nextCall) {
|
|
return nextStart;
|
|
}
|
|
nextStart += 2;
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
/*
|
|
Parse the most recent match
|
|
*/
|
|
exports.parse = function() {
|
|
var call = this.nextCall;
|
|
this.nextCall = null;
|
|
this.parser.pos = call.end;
|
|
return [call];
|
|
};
|
|
|
|
})();
|