From 9e917e235a8e7fecb37ac020ef50b4d5667efd73 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 20 Jul 2010 22:44:39 -0500 Subject: [PATCH] Support external links. --- lib/gollum/markup.rb | 12 ++++++++---- test/test_markup.rb | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 097fd9c9..cd15e17e 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -184,7 +184,7 @@ module Gollum path = parts[1] && parts[1].strip path = if path && file = find_file(path) ::File.join @wiki.base_path, file.path - elsif path =~ /^https?:\/\/.+(jpg|png|gif|svg|bmp)$/ + elsif path =~ %r{^https?://} path else nil @@ -209,9 +209,13 @@ module Gollum parts = tag.split('|') name = parts[0].strip cname = Page.cname((parts[1] || parts[0]).strip) - link = ::File.join(@wiki.base_path, cname) - presence = @wiki.page(cname) ? "present" : "absent" - %{#{name}} + if name =~ %r{^https?://} && parts[1].nil? + %{#{name}} + else + link = ::File.join(@wiki.base_path, cname) + presence = @wiki.page(cname) ? "present" : "absent" + %{#{name}} + end end # Find the given file in the repo. diff --git a/test/test_markup.rb b/test/test_markup.rb index 5316f02e..904df5e7 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -63,6 +63,13 @@ context "Markup" do end end + test "external page link" do + @wiki.write_page("Bilbo Baggins", :markdown, "a [[http://example.com]] b", @commit) + + page = @wiki.page("Bilbo Baggins") + assert_equal "

a http://example.com b

", page.formatted_data + end + test "image with http url" do ['http', 'https'].each do |scheme| @wiki.write_page("Bilbo Baggins", :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", @commit)