From e6315dbdeb698802c1c16e86ef780dc0accb15c5 Mon Sep 17 00:00:00 2001 From: buggyj Date: Wed, 16 Apr 2014 13:20:40 +0100 Subject: [PATCH] added global macrodefs file for tw2 parser, and typed blocks --- plugins/tiddlywiki/tw2parser/macrodefs.tid | 12 +++++++ plugins/tiddlywiki/tw2parser/wikitextrules.js | 36 +++++++++++-------- 2 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 plugins/tiddlywiki/tw2parser/macrodefs.tid diff --git a/plugins/tiddlywiki/tw2parser/macrodefs.tid b/plugins/tiddlywiki/tw2parser/macrodefs.tid new file mode 100644 index 000000000..1bed24365 --- /dev/null +++ b/plugins/tiddlywiki/tw2parser/macrodefs.tid @@ -0,0 +1,12 @@ +title: $:/plugins/tiddlywiki/tw2parser/macrodefs + +\define tiddler(t) +{{$t$}} +\end + +\define slider(chkUniqueCookieName tiddler label tooltip) +<$button popup="$chkUniqueCookieName$" class="btn-invisible tw-slider">$label$ +<$reveal type="nomatch" text="" default="" state="$chkUniqueCookieName$" animate="yes"> +{{$tiddler$}} + +\end diff --git a/plugins/tiddlywiki/tw2parser/wikitextrules.js b/plugins/tiddlywiki/tw2parser/wikitextrules.js index 2b1ac6da6..afa065d84 100755 --- a/plugins/tiddlywiki/tw2parser/wikitextrules.js +++ b/plugins/tiddlywiki/tw2parser/wikitextrules.js @@ -431,36 +431,41 @@ var rules = [ enclosedTextHelper.call(this,w); } }, -/* + { name: "typedBlock", - match: "^\\$\\$\\$(?:.*)\\n", - lookaheadRegExp: /^\$\$\$(.*)\n((?:^[^\n]*\n)+?)(^\f*\$\$\$$\n?)/mg, + match: "^\\$\\$\\$(?:[^ >\\r\\n]*)\\r?\\n", + lookaheadRegExp: /^\$\$\$([^ >\r\n]*)\n((?:^[^\n]*\r?\n)+?)(^\f*\$\$\$\r?\n?)/mg, + //match: "^\\$\\$\\$(?:[^ >\\r\\n]*)(?: *> *([^ \\r\\n]+))?\\r?\\n", + //lookaheadRegExp: /^\$\$\$([^ >\r\n]*)(?: *> *([^ \r\n]+))\n((?:^[^\n]*\n)+?)(^\f*\$\$\$$\n?)/mg, handler: function(w) { this.lookaheadRegExp.lastIndex = w.matchStart; var lookaheadMatch = this.lookaheadRegExp.exec(w.source); if(lookaheadMatch && lookaheadMatch.index == w.matchStart) { // The wikitext parsing infrastructure is horribly unre-entrant - var mimeType = lookaheadMatch[1], - content = lookaheadMatch[2], + var parseType = lookaheadMatch[1], + renderType ,//= this.match[2], + text = lookaheadMatch[2], oldOutput = w.output, oldSource = w.source, oldNextMatch = w.nextMatch, - oldChildren = w.children, - oldDependencies = w.dependencies, - parseTree = w.wiki.parseText(mimeType,content,{defaultType: "text/plain"}).tree; + oldChildren = w.children; + // Parse the block according to the specified type + var parser = $tw.wiki.parseText(parseType,text.toString(),{defaultType: "text/plain"}); + w.output = oldOutput; w.source = oldSource; w.nextMatch = oldNextMatch; w.children = oldChildren; - w.dependencies = oldDependencies; - w.output.push.apply(w.output,parseTree); + for (var i=0; i