mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-29 23:40:45 +00:00
Adding macros and prettylinks to new wikitext parser
This commit is contained in:
parent
6dae1ad35a
commit
4a9af461a6
32
core/modules/parsers/newwikitextparser/runrules/macro.js
Normal file
32
core/modules/parsers/newwikitextparser/runrules/macro.js
Normal 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 [];
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -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
|
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 new heading
|
||||||
This is a paragraph
|
This is a paragraph
|
||||||
|
Loading…
Reference in New Issue
Block a user