diff --git a/pagure/doc_utils.py b/pagure/doc_utils.py index bcbb70f..1a1fd01 100644 --- a/pagure/doc_utils.py +++ b/pagure/doc_utils.py @@ -15,7 +15,7 @@ import markupsafe import markdown -def modify_rst(rst): +def modify_rst(rst, view_file_url=None): """ Downgrade some of our rst directives if docutils is too old. """ # We catch Exception if we want :-p @@ -38,6 +38,9 @@ def modify_rst(rst): substitutions = { # pragma: no cover '.. code-block:: javascript': '::', } + if view_file_url: + substitutions['.. image:: '] = '.. image:: %s' % view_file_url + for old, new in substitutions.items(): # pragma: no cover rst = rst.replace(old, new) @@ -58,9 +61,9 @@ def modify_html(html): return html -def convert_doc(rst_string): +def convert_doc(rst_string, view_file_url=None): """ Utility to load an RST file and turn it into fancy HTML. """ - rst = modify_rst(rst_string) + rst = modify_rst(rst_string, view_file_url) overrides = {'report_level': 'quiet'} html = docutils.core.publish_parts( @@ -76,13 +79,13 @@ def convert_doc(rst_string): return html_string -def convert_readme(content, ext): +def convert_readme(content, ext, view_file_url=None): ''' Convert the provided content according to the extension of the file provided. ''' output = content if ext and ext in ['.rst']: - output = convert_doc(content) + output = convert_doc(content, view_file_url) elif ext and ext in ['.mk']: output = markdown.markdown(content) return output diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index d733e1f..f65dc87 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -70,7 +70,11 @@ def view_repo(repo, username=None): name, ext = os.path.splitext(i.name) if name == 'README': content = repo_obj[i.oid].data - readme = pagure.doc_utils.convert_readme(content, ext) + readme = pagure.doc_utils.convert_readme( + content, ext, + view_file_url=flask.url_for( + 'view_file', username=username, + repo=repo.name, identifier=branchname, filename='')) diff_commits = [] if repo.is_fork: