mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
create syslink.js, revert extlink.js
introduces new parser for system links
This commit is contained in:
parent
8ba3e8973e
commit
795a929187
@ -3,20 +3,16 @@ title: $:/core/modules/parsers/wikiparser/rules/extlink.js
|
|||||||
type: application/javascript
|
type: application/javascript
|
||||||
module-type: wikirule
|
module-type: wikirule
|
||||||
|
|
||||||
Wiki text inline rule for external links and system tiddler links.
|
Wiki text inline rule for external links. For example:
|
||||||
Can be suppressed preceding them with `~`.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
; system tiddler
|
An external link: http://www.tiddlywiki.com/
|
||||||
: $:/config
|
|
||||||
|
|
||||||
; external link
|
A suppressed external link: ~http://www.tiddlyspace.com/
|
||||||
: http://www.tiddlywiki.com/
|
|
||||||
|
|
||||||
; suppressed external link
|
|
||||||
: ~http://www.tiddlyspace.com/
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
External links can be suppressed by preceding them with `~`.
|
||||||
|
|
||||||
\*/
|
\*/
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
@ -30,38 +26,26 @@ exports.types = {inline: true};
|
|||||||
exports.init = function(parser) {
|
exports.init = function(parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
// Regexp to match
|
// 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() {
|
exports.parse = function() {
|
||||||
var match = this.match[0];
|
|
||||||
// Move past the match
|
// Move past the match
|
||||||
this.parser.pos = this.matchRegExp.lastIndex;
|
this.parser.pos = this.matchRegExp.lastIndex;
|
||||||
// Create the link unless it is suppressed
|
// Create the link unless it is suppressed
|
||||||
if(match.substr(0,1) === "~") {
|
if(this.match[0].substr(0,1) === "~") {
|
||||||
return [{type: "text", text: match.substr(1)}];
|
return [{type: "text", text: this.match[0].substr(1)}];
|
||||||
} else if(match.substr(0,1) === "$") {
|
|
||||||
return [{
|
|
||||||
type: "link",
|
|
||||||
attributes: {
|
|
||||||
to: {type: "string", value: match}
|
|
||||||
},
|
|
||||||
children: [{
|
|
||||||
type: "text",
|
|
||||||
text: match
|
|
||||||
}]
|
|
||||||
}];
|
|
||||||
} else {
|
} else {
|
||||||
return [{
|
return [{
|
||||||
type: "element",
|
type: "element",
|
||||||
tag: "a",
|
tag: "a",
|
||||||
attributes: {
|
attributes: {
|
||||||
href: {type: "string", value: match},
|
href: {type: "string", value: this.match[0]},
|
||||||
"class": {type: "string", value: "tc-tiddlylink-external"},
|
"class": {type: "string", value: "tc-tiddlylink-external"},
|
||||||
target: {type: "string", value: "_blank"}
|
target: {type: "string", value: "_blank"}
|
||||||
},
|
},
|
||||||
children: [{
|
children: [{
|
||||||
type: "text", text: match
|
type: "text", text: this.match[0]
|
||||||
}]
|
}]
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
45
core/modules/parsers/wikiparser/rules/syslink.js
Normal file
45
core/modules/parsers/wikiparser/rules/syslink.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/parsers/wikiparser/rules/syslink.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: wikirule
|
||||||
|
|
||||||
|
Wiki text inline rule for system tiddler links.
|
||||||
|
Can be suppressed preceding them with `~`.
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
exports.name = "syslink";
|
||||||
|
exports.types = {inline: true};
|
||||||
|
|
||||||
|
exports.init = function(parser) {
|
||||||
|
this.parser = parser;
|
||||||
|
// Regexp to match
|
||||||
|
this.matchRegExp = /~?(?:\$):[^\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(match.substr(0,1) === "~") {
|
||||||
|
return [{type: "text", text: match.substr(1)}];
|
||||||
|
} else {
|
||||||
|
return [{
|
||||||
|
type: "link",
|
||||||
|
attributes: {
|
||||||
|
to: {type: "string", value: match}
|
||||||
|
},
|
||||||
|
children: [{
|
||||||
|
type: "text",
|
||||||
|
text: match
|
||||||
|
}]
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user