Commit 06d6f443677b068eb942eb94dad1dc1ca22c0eed
1 parent
817399e3
Exists in
master
and in
4 other branches
Check for wiki.
Showing
2 changed files
with
13 additions
and
3 deletions
Show diff stats
app/helpers/gitlab_markdown_helper.rb
@@ -59,10 +59,16 @@ module GitlabMarkdownHelper | @@ -59,10 +59,16 @@ module GitlabMarkdownHelper | ||
59 | end | 59 | end |
60 | end | 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 | links = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")} | 63 | links = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")} |
64 | links.each do |string| | 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 | end | 72 | end |
67 | text | 73 | text |
68 | end | 74 | end |
lib/redcarpet/render/gitlab_html.rb
@@ -34,10 +34,14 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML | @@ -34,10 +34,14 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML | ||
34 | end | 34 | end |
35 | 35 | ||
36 | def preprocess(full_document) | 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 | end | 38 | end |
39 | 39 | ||
40 | def postprocess(full_document) | 40 | def postprocess(full_document) |
41 | h.gfm(full_document) | 41 | h.gfm(full_document) |
42 | end | 42 | end |
43 | + | ||
44 | + def is_wiki? | ||
45 | + @template.instance_variable_get("@wiki") | ||
46 | + end | ||
43 | end | 47 | end |