mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +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
|
||||
module-type: wikirule
|
||||
|
||||
|
@ -32,7 +32,7 @@ var MacroCallRenderer = function(renderTree,renderContext,parseTreeNode) {
|
||||
// Substitute the macro parameters
|
||||
var text = this.substituteParameters(macro.text,this.parseTreeNode,macro);
|
||||
// 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
|
||||
this.children = this.renderTree.createRenderers(this.renderContext,childTree);
|
||||
@ -83,7 +83,7 @@ MacroCallRenderer.prototype.render = function(type) {
|
||||
|
||||
MacroCallRenderer.prototype.renderInDom = function() {
|
||||
// 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);
|
||||
// Render any child nodes
|
||||
var self = this;
|
||||
|
@ -3,6 +3,8 @@ title: $:/templates/NewPageTemplate
|
||||
\define coolmacro(p:ridiculously) This is my $p$ cool macro!
|
||||
\define me(one two)
|
||||
some<br>thing
|
||||
|
||||
New paragraph
|
||||
\end
|
||||
\define another(first:default second third:default3) that is
|
||||
|
||||
@ -11,6 +13,11 @@ some<br>thing
|
||||
*.disabled Is a
|
||||
* List!!
|
||||
|
||||
<<me red green>>
|
||||
|
||||
Inline macro call: <<me red green>>
|
||||
|
||||
|
||||
|table|k
|
||||
| this | is | a | table |
|
||||
| yes | indeed |>| it is |
|
||||
|
Loading…
Reference in New Issue
Block a user