1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-08 21:14:25 +00:00
TiddlyWiki5/core/modules/parsers/newwikitextparser/rules/prettylink.js
2012-06-05 22:54:36 +01:00

47 lines
956 B
JavaScript

/*\
title: $:/core/modules/parsers/newwikitextparser/rules/prettylink.js
type: application/javascript
module-type: wikitextrule
Wiki text run rule for pretty links. For example:
{{{
[[Introduction]]
[[Link description|TiddlerTitle]]
}}}
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports.name = "prettylink";
exports.runParser = true;
exports.regExpString = "\\[\\[";
exports.parse = function(match,isBlock) {
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",{
srcParams: {to: link},
content: [$tw.Tree.Text(text)],
wiki: this.wiki
});
this.dependencies.mergeDependencies(macroNode.dependencies);
return [macroNode];
}
return [];
};
})();