1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-27 14:48:19 +00:00

Added ability to suppress external links

This commit is contained in:
Jeremy Ruston 2012-06-05 15:14:33 +01:00
parent 9ab9c9cc42
commit e85ae59fd8
2 changed files with 19 additions and 9 deletions

View File

@ -3,7 +3,9 @@ title: $:/core/modules/parsers/newwikitextparser/rules/extlink.js
type: application/javascript
module-type: wikitextrule
Wiki text run rule for external links
Wiki text run rule for external links.
External links can be suppressed by preceding them with `~`.
\*/
(function(){
@ -16,17 +18,23 @@ exports.name = "extlink";
exports.runParser = true;
exports.regExpString = "(?:file|http|https|mailto|ftp|irc|news|data):[^\\s'\"]+(?:/|\\b)";
var unWikiLink = "~";
exports.regExpString = unWikiLink + "?(?:file|http|https|mailto|ftp|irc|news|data):[^\\s'\"]+(?:/|\\b)";
exports.parse = function(match,isBlock) {
this.pos = match.index + match[0].length;
var macroNode = $tw.Tree.Macro("link",{
srcParams: {to: match[0]},
content: [$tw.Tree.Text(match[0])],
wiki: this.wiki
});
this.dependencies.mergeDependencies(macroNode.dependencies);
return [macroNode];
if(match[0].substr(0,1) === unWikiLink) {
return [$tw.Tree.Text(match[0].substr(1))];
} else {
var macroNode = $tw.Tree.Macro("link",{
srcParams: {to: match[0]},
content: [$tw.Tree.Text(match[0])],
wiki: this.wiki
});
this.dependencies.mergeDependencies(macroNode.dependencies);
return [macroNode];
}
};
})();

View File

@ -7,6 +7,8 @@ HelloThere
One two three four. With a link to HelloThere. And a link to TiddlyWiki and TiddlyWiki5. And a suppressed link to ~HelloThere. And now a [[pretty link|HelloThere]] and another pretty link: [[Introduction]].
Here's an http link: http://www.google.com/, and a suppressed link: ~http://www.apple.com/.
Here's a paragraph with an embedded macro <<image "Motovun Jack.jpg">> and that was it.
{{{