From 06d6f443677b068eb942eb94dad1dc1ca22c0eed Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Oct 2013 14:21:01 +0200 Subject: [PATCH] Check for wiki. --- app/helpers/gitlab_markdown_helper.rb | 10 ++++++++-- lib/redcarpet/render/gitlab_html.rb | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 1ec82cd5701..fcb7f91db9c 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -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 diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index 2277caef953..b03c4dbfe1b 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -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