patx/hglab
Add markdown links to profile bios, issue comments, and pr comments
Commit 432c1cc73a05 · Harrison Erd · 2026-05-03 23:30 -0400
Comments
No comments yet.
Diff
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -85,8 +85,8 @@
"td": ["align"],
"th": ["align"],
}
-REPO_DESCRIPTION_MARKDOWN_TAGS = {"a"}
-REPO_DESCRIPTION_MARKDOWN_ATTRIBUTES = {"a": ["href", "title"]}
+MARKDOWN_LINK_TAGS = {"a"}
+MARKDOWN_LINK_ATTRIBUTES = {"a": ["href", "title"]}
HIGHLIGHT_LANGUAGE_BY_EXTENSION = {
".c": "language-c",
".cc": "language-cpp",
@@ -364,7 +364,7 @@
context.setdefault("user", current_user())
context.setdefault("error", None)
context.setdefault("notice", None)
- context.setdefault("render_repo_description", render_repo_description)
+ context.setdefault("render_markdown_links", render_markdown_links)
return template(template_name, **context)
@@ -857,15 +857,15 @@
)
-def render_repo_description(text):
+def render_markdown_links(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,
+ tags=MARKDOWN_LINK_TAGS,
+ attributes=MARKDOWN_LINK_ATTRIBUTES,
protocols={"http", "https", "mailto"},
strip=True,
).strip()
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>
- {{!render_repo_description(repo["description"]) or "No description yet."}}
+ {{!render_markdown_links(repo["description"]) or "No description yet."}}
<br>
<br>
% end
diff --git a/templates/issue_detail.tpl b/templates/issue_detail.tpl
--- a/templates/issue_detail.tpl
+++ b/templates/issue_detail.tpl
@@ -42,7 +42,7 @@
% for comment in comments:
<article class="comment">
<p class="muted">{{comment["author_username"]}} commented on {{comment["created_at"]}}</p>
- <pre class="readme">{{comment["body"]}}</pre>
+ <pre class="readme">{{!render_markdown_links(comment["body"])}}</pre>
</article>
% end
</div>
diff --git a/templates/profile.tpl b/templates/profile.tpl
--- a/templates/profile.tpl
+++ b/templates/profile.tpl
@@ -7,7 +7,7 @@
<p class="muted">@{{profile_user["username"]}}</p>
% end
% if profile_user["bio"]:
- <p>{{profile_user["bio"]}}</p>
+ <p>{{!render_markdown_links(profile_user["bio"])}}</p>
% else:
<p class="empty">No bio yet.</p>
% end
@@ -33,7 +33,7 @@
<a style="color:black;" href="/{{repo['owner_username']}}/{{repo['name']}}">
<strong>{{repo["owner_username"]}}/{{repo["name"]}}</strong></a>
<br>
- {{!render_repo_description(repo["description"]) or "No description yet."}}
+ {{!render_markdown_links(repo["description"]) or "No description yet."}}
<br>
<small>Updated {{repo["updated_at"]}} · {{repo["star_count"]}} stars</small>
<br>
diff --git a/templates/pull_request_detail.tpl b/templates/pull_request_detail.tpl
--- a/templates/pull_request_detail.tpl
+++ b/templates/pull_request_detail.tpl
@@ -47,7 +47,7 @@
% for comment in comments:
<article class="comment">
<p class="muted">{{comment["author_username"]}} commented on {{comment["created_at"]}}</p>
- <pre class="readme">{{comment["body"]}}</pre>
+ <pre class="readme">{{!render_markdown_links(comment["body"])}}</pre>
</article>
% end
</div>
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>{{!render_repo_description(repo["description"]) or "No description yet."}}</p>
+ <p>{{!render_markdown_links(repo["description"]) or "No description yet."}}</p>
</div>
<div class="clone-box">
<code>$ hg clone {{clone_url}}</code>