From 817399e3be6bda06ed7b4c61eb8192a532ed735e Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 8 Oct 2013 13:02:30 +0200 Subject: [PATCH] Show links with correct ref. --- app/helpers/gitlab_markdown_helper.rb | 8 ++++---- lib/redcarpet/render/gitlab_html.rb | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index ae6ba46ffb7..1ec82cd5701 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -59,10 +59,10 @@ module GitlabMarkdownHelper end end - def create_relative_links(text, project_path_with_namespace) - to_be_fixed = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")} - to_be_fixed.each do |string| - text.gsub!(string, "/#{project_path_with_namespace}/blob/master/#{string}") + def create_relative_links(text, project_path_with_namespace, ref) + 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}") end text end diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index c0e858bab7d..2277caef953 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -6,6 +6,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML def initialize(template, options = {}) @template = template @project = @template.instance_variable_get("@project") + @ref = @template.instance_variable_get("@ref") super options end @@ -33,7 +34,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML end def preprocess(full_document) - h.create_relative_links(full_document, @project.path_with_namespace) + h.create_relative_links(full_document, @project.path_with_namespace, @ref) end def postprocess(full_document) -- GitLab