~edwargix/git.sr.ht

0d1762f16b68d2e263b5343fb013117e086b3bef — Drew DeVault 5 years ago a4944b0
blob view: add rendered markdown view
3 files changed, 43 insertions(+), 1 deletions(-)

M gitsrht/blueprints/repo.py
M gitsrht/templates/blob.html
M scss/main.scss
M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +4 -1
@@ 218,11 218,14 @@ 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")
                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=commit,
                        highlight_file=_highlight_file,
                        editorconfig=editorconfig)
                        editorconfig=editorconfig,
                        markdown=markdown, force_source=force_source)
            tree = git_repo.get(entry.id)

        if not tree:

M gitsrht/templates/blob.html => gitsrht/templates/blob.html +28 -0
@@ 59,12 59,39 @@ pre, body {
    {% endif %}
  </div>
</div>
{% if markdown %}
<div class="container-fluid markdown-nav">
  <ul class="nav nav-tabs">
    <li class="nav-item">
      <a
        class="nav-link {{"active" if not force_source else ""}}"
        href="?view-rendered"
      >View Rendered</a>
    </li>
    <li class="nav-item">
      <a
        class="nav-link {{"active" if force_source else ""}}"
        href="?view-source"
      >View Source</a>
    </li>
  </ul>
</div>
{% endif %}
{% if markdown and not force_source %}
<div class="container">
{% else %}
<div class="container-fluid" style="padding-left: 0; padding-right: 0;">
{% endif %}
  {#
    This row has some weird styles going on. This prevents the page from
    scrolling horizontally
  #}
  <div class="row" style="margin-right: 0;">
    {% if markdown and not force_source %}
    <div class="col-md-10 offset-md-1" style="margin-top: 1rem">
      {{ data | extended_md }}
    </div>
    {% else %}
    {% if not blob.is_binary %}
    <div class="col-md-12 code-view">
      <pre class="ruler"><span>{% for i in range(


@@ 97,6 124,7 @@ pre, body {
      </div>
    </div>
    {% endif %}
    {% endif %}
</div>
{% endblock %}


M scss/main.scss => scss/main.scss +11 -0
@@ 303,3 303,14 @@ img {
    }
  }
}

.markdown-nav {
  padding-left: 0;
  padding-right: 0;

  .nav-tabs {
    padding-left: 0;
    margin-bottom: 0;
    border-left: 1rem #ddd solid;
  }
}