From 8ba3e8973e67eb09d131539eb0d2816b90216733 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Thu, 8 Jan 2015 21:26:48 +0100 Subject: [PATCH 1/3] 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 --- .../parsers/wikiparser/rules/extlink.js | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/core/modules/parsers/wikiparser/rules/extlink.js b/core/modules/parsers/wikiparser/rules/extlink.js index 539d0f11b..b9df988be 100644 --- a/core/modules/parsers/wikiparser/rules/extlink.js +++ b/core/modules/parsers/wikiparser/rules/extlink.js @@ -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 }] }]; } }; -})(); +})(); \ No newline at end of file From 795a9291870d2fda636f22375cd841eb3e8b3257 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Fri, 9 Jan 2015 23:51:07 +0100 Subject: [PATCH 2/3] create syslink.js, revert extlink.js introduces new parser for system links --- .../parsers/wikiparser/rules/extlink.js | 38 +++++----------- .../parsers/wikiparser/rules/syslink.js | 45 +++++++++++++++++++ 2 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 core/modules/parsers/wikiparser/rules/syslink.js diff --git a/core/modules/parsers/wikiparser/rules/extlink.js b/core/modules/parsers/wikiparser/rules/extlink.js index b9df988be..539d0f11b 100644 --- a/core/modules/parsers/wikiparser/rules/extlink.js +++ b/core/modules/parsers/wikiparser/rules/extlink.js @@ -3,20 +3,16 @@ title: $:/core/modules/parsers/wikiparser/rules/extlink.js type: application/javascript module-type: wikirule -Wiki text inline rule for external links and system tiddler links. -Can be suppressed preceding them with `~`. +Wiki text inline rule for external links. For example: ``` -; system tiddler -: $:/config +An external link: http://www.tiddlywiki.com/ -; external link -: http://www.tiddlywiki.com/ - -; suppressed external link -: ~http://www.tiddlyspace.com/ +A suppressed external link: ~http://www.tiddlyspace.com/ ``` +External links can be suppressed by preceding them with `~`. + \*/ (function(){ @@ -30,41 +26,29 @@ 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(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 - }] - }]; + if(this.match[0].substr(0,1) === "~") { + return [{type: "text", text: this.match[0].substr(1)}]; } else { return [{ type: "element", tag: "a", attributes: { - href: {type: "string", value: match}, + href: {type: "string", value: this.match[0]}, "class": {type: "string", value: "tc-tiddlylink-external"}, target: {type: "string", value: "_blank"} }, children: [{ - type: "text", text: match + type: "text", text: this.match[0] }] }]; } }; -})(); \ No newline at end of file +})(); diff --git a/core/modules/parsers/wikiparser/rules/syslink.js b/core/modules/parsers/wikiparser/rules/syslink.js new file mode 100644 index 000000000..d38b6dcf3 --- /dev/null +++ b/core/modules/parsers/wikiparser/rules/syslink.js @@ -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 + }] + }]; + } +}; + +})(); \ No newline at end of file From b43d4a33d6408d1855d1b410195083062ac64e9f Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Sun, 11 Jan 2015 11:04:02 +0100 Subject: [PATCH 3/3] simplified regexp Ok, I think I've got it now. The following matches all... 1. starting with a literal `$:` 2. then any number of character not a whitespace, `<` or `|` 3. closing with anything that is, again, not a whitespace, `<` or `|` Test here... http://tbdemo.tiddlyspot.com/#Autolink%20System%20Tiddlers --- core/modules/parsers/wikiparser/rules/syslink.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/parsers/wikiparser/rules/syslink.js b/core/modules/parsers/wikiparser/rules/syslink.js index d38b6dcf3..79c0a0df8 100644 --- a/core/modules/parsers/wikiparser/rules/syslink.js +++ b/core/modules/parsers/wikiparser/rules/syslink.js @@ -18,7 +18,7 @@ exports.types = {inline: true}; exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /~?(?:\$):[^\s<>{}\[\]`|'"\\^~]+(?:\/|\b)/mg; + this.matchRegExp = /~?\$:[^\s<|]+(?:[^\s<|])/mg; }; exports.parse = function() {