From cceeb7f86f9c75d3aaba27bdc0e6b772e08c2b0d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 30 Mar 2020 10:34:07 -0400 Subject: [PATCH] Fix images in rendered markdown in blob view --- gitsrht/blueprints/repo.py | 14 ++++++++++++-- gitsrht/templates/blob.html | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index cf03d1c..2d9fef1 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -223,14 +223,24 @@ def tree(owner, repo, ref, path): data = blob.data.decode() except: data = '[unable to decode]' - markdown = not blob.is_binary and entry.name.endswith(".md") + md = not blob.is_binary and entry.name.endswith(".md") + if md: + link_prefix = url_for('repo.tree', owner=repo.owner, + repo=repo.name, ref=ref, + path=os.path.dirname("/".join(path))) + blob_prefix = url_for( + 'repo.raw_blob', owner=repo.owner, repo=repo.name, + ref=ref, path=os.path.dirname("/".join(path))) + md = markdown(data, ["h1", "h2", "h3", "h4", "h5"], + link_prefix=[link_prefix, blob_prefix]) + print(md) force_source = "view-source" in request.args return render_template("blob.html", view="blob", owner=owner, repo=repo, ref=ref, path=path, entry=entry, blob=blob, data=data, commit=orig_commit, highlight_file=_highlight_file, editorconfig=editorconfig, - markdown=markdown, force_source=force_source) + markdown=md, force_source=force_source) tree = git_repo.get(entry.id) if not tree: diff --git a/gitsrht/templates/blob.html b/gitsrht/templates/blob.html index a3144fb..2531f72 100644 --- a/gitsrht/templates/blob.html +++ b/gitsrht/templates/blob.html @@ -89,7 +89,7 @@ pre, body {
{% if markdown and not force_source %}
- {{ data | extended_md }} + {{ markdown }}
{% else %} {% if not blob.is_binary %} -- 2.38.4