2012-12-15 17:35:35 +00:00
|
|
|
/*\
|
2012-12-20 16:41:06 +00:00
|
|
|
title: $:/core/modules/parsers/wikiparser/rules/prettylink.js
|
2012-12-15 17:35:35 +00:00
|
|
|
type: application/javascript
|
2012-12-20 16:02:03 +00:00
|
|
|
module-type: wikirule
|
2012-12-15 17:35:35 +00:00
|
|
|
|
2012-12-20 12:18:38 +00:00
|
|
|
Wiki text inline rule for pretty links. For example:
|
2012-12-15 17:35:35 +00:00
|
|
|
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-15 17:35:35 +00:00
|
|
|
[[Introduction]]
|
|
|
|
|
|
|
|
[[Link description|TiddlerTitle]]
|
2012-12-22 23:09:44 +00:00
|
|
|
```
|
2012-12-15 17:35:35 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.name = "prettylink";
|
2012-12-20 16:02:03 +00:00
|
|
|
exports.types = {inline: true};
|
2012-12-15 17:35:35 +00:00
|
|
|
|
|
|
|
exports.init = function(parser) {
|
|
|
|
this.parser = parser;
|
|
|
|
// Regexp to match
|
|
|
|
this.matchRegExp = /\[\[(.*?)(?:\|(.*?))?\]\]/mg;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.parse = function() {
|
|
|
|
// Move past the match
|
|
|
|
this.parser.pos = this.matchRegExp.lastIndex;
|
|
|
|
// Process the link
|
|
|
|
var text = this.match[1],
|
|
|
|
link = this.match[2] || text;
|
|
|
|
return [{
|
2013-01-03 16:27:55 +00:00
|
|
|
type: "element",
|
|
|
|
tag: "$link",
|
2012-12-15 17:35:35 +00:00
|
|
|
attributes: {
|
|
|
|
to: {type: "string", value: link}
|
|
|
|
},
|
|
|
|
children: [{
|
|
|
|
type: "text", text: text
|
|
|
|
}]
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|