mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-07-04 19:12:51 +00:00
Added support for block macro calls
This commit is contained in:
parent
b0893956bc
commit
015145952d
60
core/modules/parsers/wikiparser/rules/macrocallblock.js
Normal file
60
core/modules/parsers/wikiparser/rules/macrocallblock.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/parsers/wikiparser/rules/macrocallblock.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: wikirule
|
||||||
|
|
||||||
|
Wiki rule for block macro calls
|
||||||
|
|
||||||
|
{{{
|
||||||
|
<<name value value2>>
|
||||||
|
}}}
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.name = "macrocall";
|
||||||
|
exports.types = {block: true};
|
||||||
|
|
||||||
|
exports.init = function(parser) {
|
||||||
|
this.parser = parser;
|
||||||
|
// Regexp to match
|
||||||
|
this.matchRegExp = /<<([^\s>]+)\s*([\s\S]*?)>>(?:\r?\n|$)/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,
|
||||||
|
isBlock: true
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -1,5 +1,5 @@
|
|||||||
/*\
|
/*\
|
||||||
title: $:/core/modules/parsers/wikiparser/rules/macrocall.js
|
title: $:/core/modules/parsers/wikiparser/rules/macrocallinline.js
|
||||||
type: application/javascript
|
type: application/javascript
|
||||||
module-type: wikirule
|
module-type: wikirule
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ var MacroCallRenderer = function(renderTree,renderContext,parseTreeNode) {
|
|||||||
// Substitute the macro parameters
|
// Substitute the macro parameters
|
||||||
var text = this.substituteParameters(macro.text,this.parseTreeNode,macro);
|
var text = this.substituteParameters(macro.text,this.parseTreeNode,macro);
|
||||||
// Parse the text
|
// Parse the text
|
||||||
childTree = this.renderTree.wiki.new_parseText("text/vnd.tiddlywiki",text).tree;
|
childTree = this.renderTree.wiki.new_parseText("text/vnd.tiddlywiki",text,{parseAsInline: !this.parseTreeNode.isBlock}).tree;
|
||||||
}
|
}
|
||||||
// Create the renderers for the child nodes
|
// Create the renderers for the child nodes
|
||||||
this.children = this.renderTree.createRenderers(this.renderContext,childTree);
|
this.children = this.renderTree.createRenderers(this.renderContext,childTree);
|
||||||
@ -83,7 +83,7 @@ MacroCallRenderer.prototype.render = function(type) {
|
|||||||
|
|
||||||
MacroCallRenderer.prototype.renderInDom = function() {
|
MacroCallRenderer.prototype.renderInDom = function() {
|
||||||
// Create the element
|
// Create the element
|
||||||
this.domNode = document.createElement("span");
|
this.domNode = document.createElement(this.parseTreeNode.isBlock ? "div" : "span");
|
||||||
this.domNode.setAttribute("data-macro-name",this.parseTreeNode.name);
|
this.domNode.setAttribute("data-macro-name",this.parseTreeNode.name);
|
||||||
// Render any child nodes
|
// Render any child nodes
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -3,6 +3,8 @@ title: $:/templates/NewPageTemplate
|
|||||||
\define coolmacro(p:ridiculously) This is my $p$ cool macro!
|
\define coolmacro(p:ridiculously) This is my $p$ cool macro!
|
||||||
\define me(one two)
|
\define me(one two)
|
||||||
some<br>thing
|
some<br>thing
|
||||||
|
|
||||||
|
New paragraph
|
||||||
\end
|
\end
|
||||||
\define another(first:default second third:default3) that is
|
\define another(first:default second third:default3) that is
|
||||||
|
|
||||||
@ -11,6 +13,11 @@ some<br>thing
|
|||||||
*.disabled Is a
|
*.disabled Is a
|
||||||
* List!!
|
* List!!
|
||||||
|
|
||||||
|
<<me red green>>
|
||||||
|
|
||||||
|
Inline macro call: <<me red green>>
|
||||||
|
|
||||||
|
|
||||||
|table|k
|
|table|k
|
||||||
| this | is | a | table |
|
| this | is | a | table |
|
||||||
| yes | indeed |>| it is |
|
| yes | indeed |>| it is |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user