Same changes from the patches sent to git.sr.ht with an external line
counter and other small changes as well as a 512KB limit on file sizes
being rendered
---
pastesrht/blueprints/public.py | 8 +++++++-
pastesrht/templates/new-paste.html | 2 ++
pastesrht/templates/paste.html | 30 +++++++++++++++++++++++++-----
pastesrht/templates/pastes.html | 1 +
4 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/pastesrht/blueprints/public.py b/pastesrht/blueprints/public.py
index 08debee..497914e 100644
--- a/pastesrht/blueprints/public.py
+++ b/pastesrht/blueprints/public.py
@@ -140,6 +140,12 @@ def highlight_file(name, content):
html = f"<style>{style}</style>" + highlight(content, lexer, formatter)
return Markup(html)
+def linecounter(count):
+ out = []
+ for i in range(1, count + 1):
+ out.append('<a href="#L{}" id="L{}">{}\n</a>'.format(i, i, i))
+ return "".join(out)
+
@public.route("/~<user>")
def pastes_user(user):
user = get_user_or_abort(user)
@@ -165,7 +171,7 @@ def pastes_user(user):
def paste_GET(user, sha):
user, paste = get_paste_or_abort(user, sha)
return render_template("paste.html", paste=paste,
- highlight_file=highlight_file)
+ highlight_file=highlight_file, linecounter=linecounter)
@public.route("/~<user>/<sha>/manage")
def paste_manage(user, sha):
diff --git a/pastesrht/templates/new-paste.html b/pastesrht/templates/new-paste.html
index e828840..a3d818d 100644
--- a/pastesrht/templates/new-paste.html
+++ b/pastesrht/templates/new-paste.html
@@ -21,6 +21,7 @@
<div class="form-group">
<input
type="text"
+ dir="auto"
id="filename"
name="filename"
class="form-control {{valid.cls('filename')}}"
@@ -30,6 +31,7 @@
</div>
<div class="form-group">
<textarea
+ dir="auto"
name="contents"
id="contents"
class="form-control {{valid.cls('contents')}}"
diff --git a/pastesrht/templates/paste.html b/pastesrht/templates/paste.html
index 3ddcd4b..df616d9 100644
--- a/pastesrht/templates/paste.html
+++ b/pastesrht/templates/paste.html
@@ -40,15 +40,35 @@
</div>
{% else %}
<div class="container-fluid other-content">
+{% if len(file.blob.contents) > 512000 %}
+ <div class="col-md-12">
+ <div style="padding: 1rem">
+ <p>
+ <span title="{{ len(file.blob.contents) }} bytes">
+ {{humanize.naturalsize(len(file.blob.contents),
+ binary=True).replace("Byte", "byte")}}
+ </span>
+ large file not shown.
+ </p>
+ <p>
+ <a href="{{ url_for(".blob_GET", sha=file.blob.sha) }}"
+ class="btn btn-primary"
+ rel="nofollow"
+ >Download {{icon("caret-right")}}</a>
+ </p>
+ </div>
+ </div>
+
+{% else %}
<div class="code-view">
+ {% autoescape off %}
<pre class="ruler"><span>{% for i in range(80) %} {% endfor %}</span></pre>
- <pre class="lines">{% for line in file.blob.contents.split("\n") %}<a
- href="#{{file.filename}}-L{{loop.index}}"
- id="{{file.filename}}-L{{loop.index}}"
- >{{loop.index}}</a>{% if not loop.last %}
-{% endif %}{% endfor %}</pre>
+ {% set lines = file.blob.contents.splitlines()|length %}
+ <pre class="lines">{{ linecounter(lines) }}</pre>
+ {% endautoescape %}
{{highlight_file(file.filename or "", file.blob.contents)}}
</div>
+{% endif %}
</div>
{% endif %}
{% endfor %}
diff --git a/pastesrht/templates/pastes.html b/pastesrht/templates/pastes.html
index 1793d0a..88475a7 100644
--- a/pastesrht/templates/pastes.html
+++ b/pastesrht/templates/pastes.html
@@ -39,6 +39,7 @@
<input
name="search"
type="text"
+ dir="auto"
placeholder="Search pastes... filename visibility:unlisted sha:d54e32b"
class="form-control{% if search_error %} is-invalid{% endif %}"
value="{{ search if search else "" }}" />
--
2.42.0