2012-05-26 22:37:44 +00:00
|
|
|
/*\
|
2012-06-02 08:54:00 +00:00
|
|
|
title: $:/core/modules/parsers/newwikitextparser/rules/prettylink.js
|
2012-05-26 22:37:44 +00:00
|
|
|
type: application/javascript
|
2012-05-27 08:19:37 +00:00
|
|
|
module-type: wikitextrule
|
2012-05-26 22:37:44 +00:00
|
|
|
|
2012-06-05 21:54:36 +00:00
|
|
|
Wiki text run rule for pretty links. For example:
|
|
|
|
|
|
|
|
{{{
|
|
|
|
[[Introduction]]
|
|
|
|
|
|
|
|
[[Link description|TiddlerTitle]]
|
|
|
|
}}}
|
2012-05-26 22:37:44 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.name = "prettylink";
|
|
|
|
|
2012-05-26 23:22:58 +00:00
|
|
|
exports.runParser = true;
|
|
|
|
|
2012-05-26 22:37:44 +00:00
|
|
|
exports.regExpString = "\\[\\[";
|
|
|
|
|
2012-05-28 14:51:52 +00:00
|
|
|
exports.parse = function(match,isBlock) {
|
2012-05-26 22:37:44 +00:00
|
|
|
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;
|
2012-05-28 14:51:52 +00:00
|
|
|
var macroNode = $tw.Tree.Macro("link",{
|
|
|
|
srcParams: {to: link},
|
|
|
|
content: [$tw.Tree.Text(text)],
|
|
|
|
wiki: this.wiki
|
|
|
|
});
|
2012-05-26 22:37:44 +00:00
|
|
|
this.dependencies.mergeDependencies(macroNode.dependencies);
|
|
|
|
return [macroNode];
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|