1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 03:57:21 +00:00

Get external links working again

We no longer use the `<$link>` widget for external links. Instead the
parser generates `<a>` 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 `<a>` element with a configurable `target` attribute
This commit is contained in:
Jeremy Ruston 2013-10-24 11:54:54 +01:00
parent d3df2c5860
commit 632970cd86
4 changed files with 44 additions and 24 deletions

View File

@ -2,7 +2,7 @@
Contributing to <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki5.html'> Contributing to <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki5.html'>
TiddlyWiki5</a></h1><p> TiddlyWiki5</a></h1><p>
<a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki5.html'> <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki5.html'>
TiddlyWiki5</a> welcomes contributions to its code and documentation via <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/https%3A%2F%2Fgithub.com%2FJermolene%2FTiddlyWiki5.html'> TiddlyWiki5</a> welcomes contributions to its code and documentation via <a href='https://github.com/Jermolene/TiddlyWiki5' target='_blank'>
GitHub</a>. Please take a moment to read these notes to help make the process as smooth as possible.</p><h2 class=''> GitHub</a>. Please take a moment to read these notes to help make the process as smooth as possible.</p><h2 class=''>
Bug Reports</h2><p> Bug Reports</h2><p>
From the perspective of the developers, a bug report that says little more than &quot;it doesn't work&quot; can be frustrating. For effective debugging, we need as much information as possible. At a minimum, please try to include:</p><ul> From the perspective of the developers, a bug report that says little more than &quot;it doesn't work&quot; can be frustrating. For effective debugging, we need as much information as possible. At a minimum, please try to include:</p><ul>
@ -14,9 +14,9 @@ Expected behaviour</li><li>
Context (OS, browser etc.)</li></ul><p> Context (OS, browser etc.)</li></ul><p>
There's a lot of good material on the web about bug reports:</p><ul> There's a lot of good material on the web about bug reports:</p><ul>
<li> <li>
<a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Fmhay68.tumblr.com%2Fpost%2F1648223018%2Fwhat-makes-a-good-bug-report.html'> <a href='http://mhay68.tumblr.com/post/1648223018/what-makes-a-good-bug-report' target='_blank'>
http://mhay68.tumblr.com/post/1648223018/what-makes-a-good-bug-report</a></li><li> http://mhay68.tumblr.com/post/1648223018/what-makes-a-good-bug-report</a></li><li>
<a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Fwww.chiark.greenend.org.uk%2F~sgtatham%2Fbugs.html.html'> <a href='http://www.chiark.greenend.org.uk/~sgtatham/bugs.html' target='_blank'>
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html</a></li></ul><h2 class=''> http://www.chiark.greenend.org.uk/~sgtatham/bugs.html</a></li></ul><h2 class=''>
Pull Requests</h2><p> Pull Requests</h2><p>
Like other <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/OpenSource.html'> Like other <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/OpenSource.html'>
@ -26,9 +26,9 @@ ContributorLicenseAgreement</a> from individual contributors before contribution
UnaMesa</a> Association (the legal entity that owns <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki.html'> UnaMesa</a> Association (the legal entity that owns <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki.html'>
TiddlyWiki</a> on behalf of the community).</p><ul> TiddlyWiki</a> on behalf of the community).</p><ul>
<li> <li>
For individuals use: <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/https%3A%2F%2Fgithub.com%2FJermolene%2FTiddlyWiki5%2Ftree%2Fmaster%2Flicenses%2Fcla-individual.md.html'> For individuals use: <a href='https://github.com/Jermolene/TiddlyWiki5/tree/master/licenses/cla-individual.md' target='_blank'>
CLA-individual</a></li><li> CLA-individual</a></li><li>
For entities use: <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/https%3A%2F%2Fgithub.com%2FJermolene%2FTiddlyWiki5%2Ftree%2Fmaster%2Flicenses%2Fcla-entity.md.html'> For entities use: <a href='https://github.com/Jermolene/TiddlyWiki5/tree/master/licenses/cla-entity.md' target='_blank'>
CLA-entity</a></li></ul><p> CLA-entity</a></li></ul><p>
<em> <em>
This is a first pass at a CLA for <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki.html'> This is a first pass at a CLA for <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki.html'>
@ -49,7 +49,7 @@ Go to your github repo and create a pull request.</strong></p><p>
<strong> <strong>
Thank you!</strong></p><h4 class=''> Thank you!</strong></p><h4 class=''>
Attribution</h4><p> Attribution</h4><p>
The CLA documents used for this project where created using <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Fwww.harmonyagreements.org.html'> The CLA documents used for this project where created using <a href='http://www.harmonyagreements.org' target='_blank'>
Harmony Project Templates</a>. &quot;HA-CLA-I-LIST Version 1.0&quot; for &quot;CLA-individual&quot; and &quot;HA-CLA-E-LIST Version 1.0&quot; for &quot;CLA-entity&quot; Harmony Project Templates</a>. &quot;HA-CLA-I-LIST Version 1.0&quot; for &quot;CLA-individual&quot; and &quot;HA-CLA-E-LIST Version 1.0&quot; for &quot;CLA-entity&quot;
</p><p> </p><p>
<em> <em>

View File

@ -26,7 +26,7 @@ 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):[^\s'"<>]+(?:\/|\b)/mg; this.matchRegExp = /~?(?:file|http|https|mailto|ftp|irc|news|data|skype):[^\s'"<>]+(?:\/|\b)/mg;
}; };
exports.parse = function() { exports.parse = function() {
@ -38,9 +38,10 @@ exports.parse = function() {
} else { } else {
return [{ return [{
type: "element", type: "element",
tag: "$link", tag: "a",
attributes: { attributes: {
to: {type: "string", value: this.match[0]} href: {type: "string", value: this.match[0]},
target: {type: "string", value: "_blank"}
}, },
children: [{ children: [{
type: "text", text: this.match[0] type: "text", text: this.match[0]

View File

@ -27,12 +27,30 @@ exports.init = function(parser) {
this.matchRegExp = /\[\[(.*?)(?:\|(.*?))?\]\]/mg; 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() { exports.parse = function() {
// Move past the match // Move past the match
this.parser.pos = this.matchRegExp.lastIndex; this.parser.pos = this.matchRegExp.lastIndex;
// Process the link // Process the link
var text = this.match[1], var text = this.match[1],
link = this.match[2] || text; link = this.match[2] || 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 [{ return [{
type: "element", type: "element",
tag: "$link", tag: "$link",
@ -43,6 +61,7 @@ exports.parse = function() {
type: "text", text: text type: "text", text: text
}] }]
}]; }];
}
}; };
})(); })();

View File

@ -10,13 +10,13 @@ node.js application</a>.</p><p>
TiddlyWiki5</a> is currently in alpha, meaning it is working but incomplete. It is a great time to get involved and support its <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/RoadMap.html'> TiddlyWiki5</a> is currently in alpha, meaning it is working but incomplete. It is a great time to get involved and support its <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/RoadMap.html'>
future development</a>:</p><ul> future development</a>:</p><ul>
<li> <li>
Explore its features online at <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Ffive.tiddlywiki.com%2F.html'> Explore its features online at <a href='http://five.tiddlywiki.com/' target='_blank'>
http://five.tiddlywiki.com/</a></li><li> http://five.tiddlywiki.com/</a></li><li>
Join the discussions on <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Fgroups.google.com%2Fgroup%2FTiddlyWikiDev.html'> Join the discussions on <a href='http://groups.google.com/group/TiddlyWikiDev' target='_blank'>
the TiddlyWikiDev Google Group</a></li><li> the TiddlyWikiDev Google Group</a></li><li>
Get involved in the <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/https%3A%2F%2Fgithub.com%2FJermolene%2FTiddlyWiki5.html'> Get involved in the <a href='https://github.com/Jermolene/TiddlyWiki5' target='_blank'>
development on GitHub</a></li><li> development on GitHub</a></li><li>
Follow <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Ftwitter.com%2F%23!%2FTiddlyWiki.html'> Follow <a href='http://twitter.com/#!/TiddlyWiki' target='_blank'>
@TiddlyWiki on Twitter</a> for the latest news</li></ul><p> @TiddlyWiki on Twitter</a> for the latest news</li></ul><p>
<em> <em>
<a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki.html'> <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki.html'>
@ -33,7 +33,7 @@ TiddlyWikiFiles</a>. For example, the following command loads the tiddlers from
TiddlyWiki</a> HTML file and then saves one of them in HTML:</p><pre> TiddlyWiki</a> HTML file and then saves one of them in HTML:</p><pre>
node tiddlywiki.js --verbose --load mywiki.html --rendertiddler ReadMe ./readme.html</pre><p> node tiddlywiki.js --verbose --load mywiki.html --rendertiddler ReadMe ./readme.html</pre><p>
In order to use <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki5.html'> In order to use <a class=' tw-tiddlylink tw-tiddlylink-resolves' href='http://five.tiddlywiki.com/static/TiddlyWiki5.html'>
TiddlyWiki5</a> on the command line you must first install node.js from <a class=' tw-tiddlylink tw-tiddlylink-missing' href='http://five.tiddlywiki.com/static/http%3A%2F%2Fnodejs.org%2F.html'> TiddlyWiki5</a> on the command line you must first install node.js from <a href='http://nodejs.org/' target='_blank'>
http://nodejs.org/</a></p><h2 class=''> http://nodejs.org/</a></p><h2 class=''>
Usage</h2><p> Usage</h2><p>
Running <code> Running <code>