Commit 810d90dd26d98a80ffb3a4100b1c4f70b824bb70
1 parent
073c8a29
Exists in
master
and in
4 other branches
Search and replace relative links in tree/readme
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
app/helpers/gitlab_markdown_helper.rb
... | ... | @@ -34,7 +34,8 @@ module GitlabMarkdownHelper |
34 | 34 | # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch- |
35 | 35 | filter_html: true, |
36 | 36 | with_toc_data: true, |
37 | - hard_wrap: true) | |
37 | + hard_wrap: true, | |
38 | + safe_links_only: true) | |
38 | 39 | @markdown = Redcarpet::Markdown.new(gitlab_renderer, |
39 | 40 | # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use |
40 | 41 | no_intra_emphasis: true, |
... | ... | @@ -57,4 +58,12 @@ module GitlabMarkdownHelper |
57 | 58 | wiki_page.formatted_content.html_safe |
58 | 59 | end |
59 | 60 | end |
61 | + | |
62 | + def create_relative_links(text, project_path_with_namespace) | |
63 | + to_be_fixed = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")} | |
64 | + to_be_fixed.each do |string| | |
65 | + text.gsub!(string, "/#{project_path_with_namespace}/blob/master/#{string}") | |
66 | + end | |
67 | + text | |
68 | + end | |
60 | 69 | end | ... | ... |
lib/redcarpet/render/gitlab_html.rb
... | ... | @@ -32,6 +32,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML |
32 | 32 | h.link_to_gfm(content, link, title: title) |
33 | 33 | end |
34 | 34 | |
35 | + def preprocess(full_document) | |
36 | + h.create_relative_links(full_document, @project.path_with_namespace) | |
37 | + end | |
38 | + | |
35 | 39 | def postprocess(full_document) |
36 | 40 | h.gfm(full_document) |
37 | 41 | end | ... | ... |