1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

autolinks system tiddlers

enhanced extlink parser to cover system tiddler links

of course, only those without spaces in their title

didn't want to open up an extra parser for this as extlink has all the
basics
This commit is contained in:
Tobias Beer 2015-01-08 21:26:48 +01:00
parent 978cc2e173
commit 8ba3e8973e

View File

@ -3,16 +3,20 @@ title: $:/core/modules/parsers/wikiparser/rules/extlink.js
type: application/javascript
module-type: wikirule
Wiki text inline rule for external links. For example:
Wiki text inline rule for external links and system tiddler links.
Can be suppressed preceding them with `~`.
```
An external link: http://www.tiddlywiki.com/
; system tiddler
: $:/config
A suppressed external link: ~http://www.tiddlyspace.com/
; external link
: http://www.tiddlywiki.com/
; suppressed external link
: ~http://www.tiddlyspace.com/
```
External links can be suppressed by preceding them with `~`.
\*/
(function(){
@ -26,29 +30,41 @@ exports.types = {inline: true};
exports.init = function(parser) {
this.parser = parser;
// Regexp to match
this.matchRegExp = /~?(?:file|http|https|mailto|ftp|irc|news|data|skype):[^\s<>{}\[\]`|'"\\^~]+(?:\/|\b)/mg;
this.matchRegExp = /~?(?:\$|file|http|https|mailto|ftp|irc|news|data|skype):[^\s<>{}\[\]`|'"\\^~]+(?:\/|\b)/mg;
};
exports.parse = function() {
var match = this.match[0];
// Move past the match
this.parser.pos = this.matchRegExp.lastIndex;
// Create the link unless it is suppressed
if(this.match[0].substr(0,1) === "~") {
return [{type: "text", text: this.match[0].substr(1)}];
if(match.substr(0,1) === "~") {
return [{type: "text", text: match.substr(1)}];
} else if(match.substr(0,1) === "$") {
return [{
type: "link",
attributes: {
to: {type: "string", value: match}
},
children: [{
type: "text",
text: match
}]
}];
} else {
return [{
type: "element",
tag: "a",
attributes: {
href: {type: "string", value: this.match[0]},
href: {type: "string", value: match},
"class": {type: "string", value: "tc-tiddlylink-external"},
target: {type: "string", value: "_blank"}
},
children: [{
type: "text", text: this.match[0]
type: "text", text: match
}]
}];
}
};
})();
})();