diff options
| author | Marin Jankovski <maxlazio@gmail.com> | 2013-10-08 12:24:50 +0200 |
|---|---|---|
| committer | Marin Jankovski <maxlazio@gmail.com> | 2013-10-08 12:24:50 +0200 |
| commit | 810d90dd26d98a80ffb3a4100b1c4f70b824bb70 (patch) | |
| tree | 648044746b2472948bc72a3a77efa541f6f637c5 | |
| parent | 073c8a296668ab1e06b01ebf0a9e94786227eef4 (diff) | |
| download | gitlab-ce-810d90dd26d98a80ffb3a4100b1c4f70b824bb70.tar.gz | |
Search and replace relative links in tree/readme
| -rw-r--r-- | app/helpers/gitlab_markdown_helper.rb | 11 | ||||
| -rw-r--r-- | lib/redcarpet/render/gitlab_html.rb | 4 |
2 files changed, 14 insertions, 1 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index 375f8861dae..ae6ba46ffb7 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -34,7 +34,8 @@ module GitlabMarkdownHelper # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch- filter_html: true, with_toc_data: true, - hard_wrap: true) + hard_wrap: true, + safe_links_only: true) @markdown = Redcarpet::Markdown.new(gitlab_renderer, # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use no_intra_emphasis: true, @@ -57,4 +58,12 @@ module GitlabMarkdownHelper wiki_page.formatted_content.html_safe 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}") + end + text + end end diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb index d9c2d3b626d..c0e858bab7d 100644 --- a/lib/redcarpet/render/gitlab_html.rb +++ b/lib/redcarpet/render/gitlab_html.rb @@ -32,6 +32,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML h.link_to_gfm(content, link, title: title) end + def preprocess(full_document) + h.create_relative_links(full_document, @project.path_with_namespace) + end + def postprocess(full_document) h.gfm(full_document) end |
