OSDN Git Service

Check for wiki.
authorMarin Jankovski <maxlazio@gmail.com>
Tue, 8 Oct 2013 12:21:01 +0000 (14:21 +0200)
committerMarin Jankovski <maxlazio@gmail.com>
Tue, 8 Oct 2013 12:21:01 +0000 (14:21 +0200)
app/helpers/gitlab_markdown_helper.rb
lib/redcarpet/render/gitlab_html.rb

index 1ec82cd..fcb7f91 100644 (file)
@@ -59,10 +59,16 @@ module GitlabMarkdownHelper
     end
   end
 
-  def create_relative_links(text, project_path_with_namespace, ref)
+  def create_relative_links(text, project_path_with_namespace, ref, wiki = false)
     links = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")}
     links.each do |string|
-      text.gsub!(string, "/#{project_path_with_namespace}/blob/#{ref}/#{string}")
+      new_link = [
+        project_path_with_namespace,
+        wiki ? "wiki":"blob",
+        ref,
+        string
+      ].compact.join("/")
+      text.gsub!(string, "/#{new_link}")
     end
     text
   end
index 2277cae..b03c4db 100644 (file)
@@ -34,10 +34,14 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
   end
 
   def preprocess(full_document)
-    h.create_relative_links(full_document, @project.path_with_namespace, @ref)
+    h.create_relative_links(full_document, @project.path_with_namespace, @ref, is_wiki?)
   end
 
   def postprocess(full_document)
     h.gfm(full_document)
   end
+
+  def is_wiki?
+    @template.instance_variable_get("@wiki")
+  end
 end