diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1766,12 +1766,12 @@ def renderer_from_filename(filename, exc return None -def render(source, renderer='rst', mentions=False, relative_url=None, +def render(source, renderer='rst', mentions=False, relative_urls=None, repo_name=None): def maybe_convert_relative_links(html_source): - if relative_url: - return relative_links(html_source, relative_url) + if relative_urls: + return relative_links(html_source, relative_urls) return html_source if renderer == 'rst': diff --git a/rhodecode/lib/markup_renderer.py b/rhodecode/lib/markup_renderer.py --- a/rhodecode/lib/markup_renderer.py +++ b/rhodecode/lib/markup_renderer.py @@ -73,7 +73,7 @@ class RhodeCodeWriter(writers.html4css1. self.translator_class = CustomHTMLTranslator -def relative_links(html_source, server_path): +def relative_links(html_source, server_paths): if not html_source: return html_source @@ -92,12 +92,16 @@ def relative_links(html_source, server_p for el in doc.cssselect('img, video'): src = el.attrib.get('src') if src: - el.attrib['src'] = relative_path(src, server_path) + el.attrib['src'] = relative_path(src, server_paths['raw']) for el in doc.cssselect('a:not(.gfm)'): src = el.attrib.get('href') if src: - el.attrib['href'] = relative_path(src, server_path) + raw_mode = el.attrib['href'].endswith('?raw=1') + if raw_mode: + el.attrib['href'] = relative_path(src, server_paths['raw']) + else: + el.attrib['href'] = relative_path(src, server_paths['standard']) return lxml.html.tostring(doc) diff --git a/rhodecode/templates/files/files_source.mako b/rhodecode/templates/files/files_source.mako --- a/rhodecode/templates/files/files_source.mako +++ b/rhodecode/templates/files/files_source.mako @@ -74,7 +74,13 @@ %else: % if c.file.size < c.visual.cut_off_limit_file: %if c.renderer and not c.annotate: - ${h.render(c.file.content, renderer=c.renderer, relative_url=h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path))} + <% + relative_urls = { + 'raw': h.route_path('repo_file_raw',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path), + 'standard': h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.f_path), + } + %> + ${h.render(c.file.content, renderer=c.renderer, relative_urls=relative_urls)} %else: