From 632970cd86e66c5b210523cd677de8012f1de0c8 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 24 Oct 2013 11:54:54 +0100 Subject: [PATCH] Get external links working again We no longer use the `<$link>` widget for external links. Instead the parser generates `` elements. This makes things simpler, but does mean that the `target=_blank` behaviour is baked into the parser. Probably we should introduce a new `<$extlink>` widget that generates an `` element with a configurable `target` attribute --- contributing.md | 12 +++--- .../parsers/wikiparser/rules/extlink.js | 7 ++-- .../parsers/wikiparser/rules/prettylink.js | 39 ++++++++++++++----- readme.md | 10 ++--- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/contributing.md b/contributing.md index 1632759db..d7f48284a 100644 --- a/contributing.md +++ b/contributing.md @@ -2,7 +2,7 @@ Contributing to TiddlyWiki5

-TiddlyWiki5 welcomes contributions to its code and documentation via +TiddlyWiki5 welcomes contributions to its code and documentation via GitHub. Please take a moment to read these notes to help make the process as smooth as possible.

Bug Reports

From the perspective of the developers, a bug report that says little more than "it doesn't work" can be frustrating. For effective debugging, we need as much information as possible. At a minimum, please try to include:

There's a lot of good material on the web about bug reports:

Pull Requests

Like other @@ -26,9 +26,9 @@ ContributorLicenseAgreement from individual contributors before contribution UnaMesa Association (the legal entity that owns TiddlyWiki on behalf of the community).

This is a first pass at a CLA for @@ -49,7 +49,7 @@ Go to your github repo and create a pull request.

Thank you!

Attribution

-The CLA documents used for this project where created using +The CLA documents used for this project where created using Harmony Project Templates. "HA-CLA-I-LIST Version 1.0" for "CLA-individual" and "HA-CLA-E-LIST Version 1.0" for "CLA-entity"

diff --git a/core/modules/parsers/wikiparser/rules/extlink.js b/core/modules/parsers/wikiparser/rules/extlink.js index 0203434f0..42c247d22 100644 --- a/core/modules/parsers/wikiparser/rules/extlink.js +++ b/core/modules/parsers/wikiparser/rules/extlink.js @@ -26,7 +26,7 @@ exports.types = {inline: true}; exports.init = function(parser) { this.parser = parser; // Regexp to match - this.matchRegExp = /~?(?:file|http|https|mailto|ftp|irc|news|data):[^\s'"<>]+(?:\/|\b)/mg; + this.matchRegExp = /~?(?:file|http|https|mailto|ftp|irc|news|data|skype):[^\s'"<>]+(?:\/|\b)/mg; }; exports.parse = function() { @@ -38,9 +38,10 @@ exports.parse = function() { } else { return [{ type: "element", - tag: "$link", + tag: "a", attributes: { - to: {type: "string", value: this.match[0]} + href: {type: "string", value: this.match[0]}, + target: {type: "string", value: "_blank"} }, children: [{ type: "text", text: this.match[0] diff --git a/core/modules/parsers/wikiparser/rules/prettylink.js b/core/modules/parsers/wikiparser/rules/prettylink.js index 2eb5eac98..0dffbf0f3 100644 --- a/core/modules/parsers/wikiparser/rules/prettylink.js +++ b/core/modules/parsers/wikiparser/rules/prettylink.js @@ -27,22 +27,41 @@ exports.init = function(parser) { this.matchRegExp = /\[\[(.*?)(?:\|(.*?))?\]\]/mg; }; +var isLinkExternal = function(to) { + var externalRegExp = /(?:file|http|https|mailto|ftp|irc|news|data|skype):[^\s'"]+(?:\/|\b)/i; + return externalRegExp.test(to); +}; + 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 [{ - type: "element", - tag: "$link", - attributes: { - to: {type: "string", value: link} - }, - children: [{ - type: "text", text: text - }] - }]; + if(isLinkExternal(link)) { + return [{ + type: "element", + tag: "a", + attributes: { + href: {type: "string", value: link}, + target: {type: "string", value: "_blank"} + }, + children: [{ + type: "text", text: text + }] + }]; + } else { + return [{ + type: "element", + tag: "$link", + attributes: { + to: {type: "string", value: link} + }, + children: [{ + type: "text", text: text + }] + }]; + } }; })(); diff --git a/readme.md b/readme.md index cfe4bb609..98cc0b8a0 100644 --- a/readme.md +++ b/readme.md @@ -10,13 +10,13 @@ node.js application.

TiddlyWiki5 is currently in alpha, meaning it is working but incomplete. It is a great time to get involved and support its future development:

@@ -33,7 +33,7 @@ TiddlyWikiFiles. For example, the following command loads the tiddlers from TiddlyWiki HTML file and then saves one of them in HTML:

 node tiddlywiki.js --verbose --load mywiki.html --rendertiddler ReadMe ./readme.html

In order to use -TiddlyWiki5 on the command line you must first install node.js from +TiddlyWiki5 on the command line you must first install node.js from http://nodejs.org/

Usage

Running