From 74e8afdcdd0d3764b1fd0fe90b155bf04eecf513 Mon Sep 17 00:00:00 2001 From: buggyj Date: Thu, 7 Jan 2016 22:11:26 +0000 Subject: [PATCH] fix for #2189 --- plugins/tiddlywiki/tw2parser/wikitextparser.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/tiddlywiki/tw2parser/wikitextparser.js b/plugins/tiddlywiki/tw2parser/wikitextparser.js index 96393eb95..6a56992f5 100644 --- a/plugins/tiddlywiki/tw2parser/wikitextparser.js +++ b/plugins/tiddlywiki/tw2parser/wikitextparser.js @@ -56,18 +56,25 @@ var WikiTextParser = function(type,text,options) { this.source = text; this.nextMatch = 0; this.children = []; - //this.children.push({type: "text",text:"hello to the queen"}); this.tree =[]; this.output = null; this.subWikify(this.children); - var parser = $tw.wiki.old_parseTiddler("$:/plugins/tiddlywiki/tw2parser/macrodefs",{parseAsInline:false}); + // prepend tw2 macros locally to the content + var parser = $tw.wiki.parseTiddler("$:/plugins/tiddlywiki/tw2parser/macrodefs",{parseAsInline:false}); this.tree = [{ type: "element", tag: "div", - children:this.children + children:this.children }]; - Array.prototype.push.apply(parser.tree,this.tree); - this.tree = parser.tree; + // clone the output of parser + var root = JSON.parse(JSON.stringify(parser.tree)); + // macros are defined in a linear tree; walk down the tree and append the source's parsed content + var baseroot = root; + while (root[0] && root[0].children && root[0].children.length !== 0 ){ + root = root[0].children; + } + root[0].children[0] = this.tree[0]; + this.tree = baseroot; };