Permalink
Browse files

Adding macros and prettylinks to new wikitext parser

  • Loading branch information...
1 parent 6dae1ad commit 4a9af461a6a907f3bcd8b9724056004345d3b7b1 @Jermolene committed May 26, 2012
@@ -0,0 +1,32 @@
+/*\
+title: $:/core/modules/parsers/newwikitextparser/runrules/macro.js
+type: application/javascript
+module-type: wikitextrunrule
+
+Wiki text run rule for pretty links
+
+\*/
+(function(){
+
+/*jslint node: true, browser: true */
+/*global $tw: false */
+"use strict";
+
+exports.name = "macro";
+
+exports.regExpString = "<<";
+
+exports.parse = function(match) {
+ var regExp = /<<(?:([!@£\$%\^\&\*\(\)`\~'"\|\\\/;\:\.\,\+\=\-\_\{\}])|([^>\s]+))(?:\s*)((?:[^>]|(?:>(?!>)))*)>>/mg;
+ regExp.lastIndex = this.pos;
+ match = regExp.exec(this.source);
+ if(match && match.index === this.pos) {
+ this.pos = match.index + match[0].length;
+ var macroNode = $tw.Tree.Macro(match[1] || match[2],match[3],[],this.wiki);
+ this.dependencies.mergeDependencies(macroNode.dependencies);
+ return [macroNode];
+ }
+ return [];
+};
+
+})();
@@ -0,0 +1,34 @@
+/*\
+title: $:/core/modules/parsers/newwikitextparser/runrules/prettylink.js
+type: application/javascript
+module-type: wikitextrunrule
+
+Wiki text run rule for pretty links
+
+\*/
+(function(){
+
+/*jslint node: true, browser: true */
+/*global $tw: false */
+"use strict";
+
+exports.name = "prettylink";
+
+exports.regExpString = "\\[\\[";
+
+exports.parse = function(match) {
+ var regExp = /\[\[(.*?)(?:\|(~)?(.*?))?\]\]/mg;
+ regExp.lastIndex = this.pos;
+ match = regExp.exec(this.source);
+ if(match && match.index === this.pos) {
+ var text = match[1],
+ link = match[3] || text;
+ this.pos = match.index + match[0].length;
+ var macroNode = $tw.Tree.Macro("link",{to: link},[$tw.Tree.Text(text)],this.wiki);
+ this.dependencies.mergeDependencies(macroNode.dependencies);
+ return [macroNode];
+ }
+ return [];
+};
+
+})();
@@ -5,7 +5,9 @@ type: text/x-tiddlywiki-new
HelloThere
-One two three four. With a link to HelloThere. And a link to TiddlyWiki and TiddlyWiki5. And a suppressed link to ~HelloThere.
+One two three four. With a link to HelloThere. And a link to TiddlyWiki and TiddlyWiki5. And a suppressed link to ~HelloThere. And now a [[pretty link|HelloThere]] and another pretty link: [[Introduction]].
+
+Here is a macro <<list all>>
! This is a new heading
This is a paragraph

0 comments on commit 4a9af46

Please sign in to comment.