From e85ae59fd8041015f82385e72e680ed15b319d1b Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 5 Jun 2012 15:14:33 +0100 Subject: [PATCH] Added ability to suppress external links --- .../newwikitextparser/rules/extlink.js | 26 ++++++++++++------- tw5.com/tiddlers/TestingNewWikiText.tid | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/modules/parsers/newwikitextparser/rules/extlink.js b/core/modules/parsers/newwikitextparser/rules/extlink.js index 11e780cf8..2bb88fe9e 100644 --- a/core/modules/parsers/newwikitextparser/rules/extlink.js +++ b/core/modules/parsers/newwikitextparser/rules/extlink.js @@ -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]; + } }; })(); diff --git a/tw5.com/tiddlers/TestingNewWikiText.tid b/tw5.com/tiddlers/TestingNewWikiText.tid index 50a01b1b0..00dc0cc4c 100644 --- a/tw5.com/tiddlers/TestingNewWikiText.tid +++ b/tw5.com/tiddlers/TestingNewWikiText.tid @@ -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 <> and that was it. {{{