mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-04-27 19:05:01 +00:00
Start introducing both inline and block variants of macro calls
This commit is contained in:
59
core/modules/parsers/wikiparser/rules/macrocallinline.js
Normal file
59
core/modules/parsers/wikiparser/rules/macrocallinline.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/*\
|
||||
title: $:/core/modules/parsers/wikiparser/rules/macrocall.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 = "macrocall";
|
||||
exports.types = {inline: true};
|
||||
|
||||
exports.init = function(parser) {
|
||||
this.parser = parser;
|
||||
// Regexp to match
|
||||
this.matchRegExp = /<<([^\s>]+)\s*([\s\S]*?)>>/mg;
|
||||
};
|
||||
|
||||
/*
|
||||
Parse the most recent match
|
||||
*/
|
||||
exports.parse = function() {
|
||||
// Get all the details of the match
|
||||
var macroName = this.match[1],
|
||||
paramString = this.match[2];
|
||||
// Move past the macro call
|
||||
this.parser.pos = this.matchRegExp.lastIndex;
|
||||
var params = [],
|
||||
reParam = /\s*(?:([A-Za-z0-9\-_]+)\s*:)?(?:\s*(?:"([^"]*)"|'([^']*)'|\[\[([^\]]*)\]\]|([^"'\s]+)))/mg,
|
||||
paramMatch = reParam.exec(paramString);
|
||||
while(paramMatch) {
|
||||
// Process this parameter
|
||||
var paramInfo = {
|
||||
value: paramMatch[2] || paramMatch[3] || paramMatch[4] || paramMatch[5]
|
||||
};
|
||||
if(paramMatch[1]) {
|
||||
paramInfo.name = paramMatch[1];
|
||||
}
|
||||
params.push(paramInfo);
|
||||
// Find the next match
|
||||
paramMatch = reParam.exec(paramString);
|
||||
}
|
||||
return [{
|
||||
type: "macrocall",
|
||||
name: macroName,
|
||||
params: params
|
||||
}];
|
||||
};
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user