Show links with correct ref.
This commit is contained in:
parent
810d90dd26
commit
817399e3be
2 changed files with 6 additions and 5 deletions
|
@ -59,10 +59,10 @@ module GitlabMarkdownHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_relative_links(text, project_path_with_namespace)
|
def create_relative_links(text, project_path_with_namespace, ref)
|
||||||
to_be_fixed = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")}
|
links = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")}
|
||||||
to_be_fixed.each do |string|
|
links.each do |string|
|
||||||
text.gsub!(string, "/#{project_path_with_namespace}/blob/master/#{string}")
|
text.gsub!(string, "/#{project_path_with_namespace}/blob/#{ref}/#{string}")
|
||||||
end
|
end
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
|
||||||
def initialize(template, options = {})
|
def initialize(template, options = {})
|
||||||
@template = template
|
@template = template
|
||||||
@project = @template.instance_variable_get("@project")
|
@project = @template.instance_variable_get("@project")
|
||||||
|
@ref = @template.instance_variable_get("@ref")
|
||||||
super options
|
super options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
def preprocess(full_document)
|
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
|
end
|
||||||
|
|
||||||
def postprocess(full_document)
|
def postprocess(full_document)
|
||||||
|
|
Loading…
Reference in a new issue