patx/hglab
allow markdown links in repo descriptions
Commit f053aba4bae9 · Harrison Erd · 2026-05-03 23:23 -0400
Comments
No comments yet.
Diff
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -2,6 +2,7 @@
import datetime as dt
import hashlib
import hmac
+import html
import mimetypes
import os
import re
@@ -84,6 +85,8 @@
"td": ["align"],
"th": ["align"],
}
+REPO_DESCRIPTION_MARKDOWN_TAGS = {"a"}
+REPO_DESCRIPTION_MARKDOWN_ATTRIBUTES = {"a": ["href", "title"]}
HIGHLIGHT_LANGUAGE_BY_EXTENSION = {
".c": "language-c",
".cc": "language-cpp",
@@ -361,6 +364,7 @@
context.setdefault("user", current_user())
context.setdefault("error", None)
context.setdefault("notice", None)
+ context.setdefault("render_repo_description", render_repo_description)
return template(template_name, **context)
@@ -853,6 +857,20 @@
)
+def render_repo_description(text):
+ rendered = markdown.markdown(
+ html.escape(text or "", quote=False),
+ output_format="html5",
+ )
+ return bleach.clean(
+ rendered,
+ tags=REPO_DESCRIPTION_MARKDOWN_TAGS,
+ attributes=REPO_DESCRIPTION_MARKDOWN_ATTRIBUTES,
+ protocols={"http", "https", "mailto"},
+ strip=True,
+ ).strip()
+
+
def commit_log(path, limit=50):
template_arg = "{rev}\\x1f{node|short}\\x1f{author|person}\\x1f{date|isodate}\\x1f{desc|firstline}\\x1e"
completed = run_hg(["log", "-l", str(limit), "--template", template_arg], cwd=path, check=False)
diff --git a/templates/index.tpl b/templates/index.tpl
--- a/templates/index.tpl
+++ b/templates/index.tpl
@@ -21,7 +21,7 @@
% for repo in repos:
<a style="color:black;" href="/{{repo['owner_username']}}/{{repo['name']}}"><strong>{{repo["owner_username"]}}/{{repo["name"]}}</strong></a>
<br>
- {{repo["description"] or "No description yet."}}
+ {{!render_repo_description(repo["description"]) or "No description yet."}}
<br>
<br>
% end
@@ -29,4 +29,3 @@
<p class="empty">No repositories yet.</p>
% end
</section>
-
diff --git a/templates/profile.tpl b/templates/profile.tpl
--- a/templates/profile.tpl
+++ b/templates/profile.tpl
@@ -33,7 +33,7 @@
<a style="color:black;" href="/{{repo['owner_username']}}/{{repo['name']}}">
<strong>{{repo["owner_username"]}}/{{repo["name"]}}</strong></a>
<br>
- {{repo["description"] or "No description yet."}}
+ {{!render_repo_description(repo["description"]) or "No description yet."}}
<br>
<small>Updated {{repo["updated_at"]}} · {{repo["star_count"]}} stars</small>
<br>
@@ -43,4 +43,3 @@
<p class="empty">{{"No starred repositories yet." if active_tab == "stars" else "No repositories yet."}}</p>
% end
</section>
-
diff --git a/templates/repo.tpl b/templates/repo.tpl
--- a/templates/repo.tpl
+++ b/templates/repo.tpl
@@ -7,7 +7,7 @@
% include("repo_nav.tpl", repo=repo, commit_count=commit_count, issue_counts=issue_counts, pr_counts=pr_counts, star_count=star_count, is_starred=is_starred, is_owner=is_owner, can_maintain=can_maintain)
- <p>{{repo["description"] or "No description yet."}}</p>
+ <p>{{!render_repo_description(repo["description"]) or "No description yet."}}</p>
</div>
<div class="clone-box">
<code>$ hg clone {{clone_url}}</code>
@@ -44,4 +44,3 @@
</div>
% end
</section>
-