diff --git a/core/modules/parsers/wikiparser/rules/macrocallblock.js b/core/modules/parsers/wikiparser/rules/macrocallblock.js new file mode 100644 index 000000000..e39815710 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/macrocallblock.js @@ -0,0 +1,60 @@ +/*\ +title: $:/core/modules/parsers/wikiparser/rules/macrocallblock.js +type: application/javascript +module-type: wikirule + +Wiki rule for block macro calls + +{{{ +<> +}}} + +\*/ +(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 + }]; +}; + +})(); diff --git a/core/modules/parsers/wikiparser/rules/macrocallinline.js b/core/modules/parsers/wikiparser/rules/macrocallinline.js index dddc23cab..4d891804f 100644 --- a/core/modules/parsers/wikiparser/rules/macrocallinline.js +++ b/core/modules/parsers/wikiparser/rules/macrocallinline.js @@ -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 diff --git a/core/modules/rendertree/renderers/macrocall.js b/core/modules/rendertree/renderers/macrocall.js index d667a5f44..f8f8767d4 100644 --- a/core/modules/rendertree/renderers/macrocall.js +++ b/core/modules/rendertree/renderers/macrocall.js @@ -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; diff --git a/core/templates/NewPageTemplate.tid b/core/templates/NewPageTemplate.tid index 6594fb41b..f0e344ed7 100644 --- a/core/templates/NewPageTemplate.tid +++ b/core/templates/NewPageTemplate.tid @@ -3,6 +3,8 @@ title: $:/templates/NewPageTemplate \define coolmacro(p:ridiculously) This is my $p$ cool macro! \define me(one two) some
thing + +New paragraph \end \define another(first:default second third:default3) that is @@ -11,6 +13,11 @@ some
thing *.disabled Is a * List!! +<> + +Inline macro call: <> + + |table|k | this | is | a | table | | yes | indeed |>| it is |