1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Adding macros and prettylinks to new wikitext parser

This commit is contained in:
Jeremy Ruston 2012-05-26 23:37:44 +01:00
parent 6dae1ad35a
commit 4a9af461a6
3 changed files with 69 additions and 1 deletions

View File

@ -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 [];
};
})();

View File

@ -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 [];
};
})();

View File

@ -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