Added ability to suppress external links

print-window-tiddler
Jeremy Ruston 2012-06-05 15:14:33 +01:00
rodzic 9ab9c9cc42
commit e85ae59fd8
2 zmienionych plików z 19 dodań i 9 usunięć

Wyświetl plik

@ -3,7 +3,9 @@ title: $:/core/modules/parsers/newwikitextparser/rules/extlink.js
type: application/javascript type: application/javascript
module-type: wikitextrule 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(){ (function(){
@ -16,10 +18,15 @@ exports.name = "extlink";
exports.runParser = true; 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) { exports.parse = function(match,isBlock) {
this.pos = match.index + match[0].length; this.pos = match.index + match[0].length;
if(match[0].substr(0,1) === unWikiLink) {
return [$tw.Tree.Text(match[0].substr(1))];
} else {
var macroNode = $tw.Tree.Macro("link",{ var macroNode = $tw.Tree.Macro("link",{
srcParams: {to: match[0]}, srcParams: {to: match[0]},
content: [$tw.Tree.Text(match[0])], content: [$tw.Tree.Text(match[0])],
@ -27,6 +34,7 @@ exports.parse = function(match,isBlock) {
}); });
this.dependencies.mergeDependencies(macroNode.dependencies); this.dependencies.mergeDependencies(macroNode.dependencies);
return [macroNode]; return [macroNode];
}
}; };
})(); })();

Wyświetl plik

@ -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]]. 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. Here's a paragraph with an embedded macro <<image "Motovun Jack.jpg">> and that was it.
{{{ {{{