Commit 06d6f443677b068eb942eb94dad1dc1ca22c0eed

Authored by Marin Jankovski
1 parent 817399e3

Check for wiki.

app/helpers/gitlab_markdown_helper.rb
... ... @@ -59,10 +59,16 @@ module GitlabMarkdownHelper
59 59 end
60 60 end
61 61  
62   - def create_relative_links(text, project_path_with_namespace, ref)
  62 + def create_relative_links(text, project_path_with_namespace, ref, wiki = false)
63 63 links = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")}
64 64 links.each do |string|
65   - text.gsub!(string, "/#{project_path_with_namespace}/blob/#{ref}/#{string}")
  65 + new_link = [
  66 + project_path_with_namespace,
  67 + wiki ? "wiki":"blob",
  68 + ref,
  69 + string
  70 + ].compact.join("/")
  71 + text.gsub!(string, "/#{new_link}")
66 72 end
67 73 text
68 74 end
... ...
lib/redcarpet/render/gitlab_html.rb
... ... @@ -34,10 +34,14 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
34 34 end
35 35  
36 36 def preprocess(full_document)
37   - h.create_relative_links(full_document, @project.path_with_namespace, @ref)
  37 + h.create_relative_links(full_document, @project.path_with_namespace, @ref, is_wiki?)
38 38 end
39 39  
40 40 def postprocess(full_document)
41 41 h.gfm(full_document)
42 42 end
  43 +
  44 + def is_wiki?
  45 + @template.instance_variable_get("@wiki")
  46 + end
43 47 end
... ...