Skip to content

Commit 37296b1

Browse files
Improve colophon rendering (#32)
## Summary - render commit messages in the colophon using Markdown formatting - reposition the page header outside the main content for correct structure ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_6921b15f58888325b2cdd1ee432a3905)
1 parent baf7475 commit 37296b1

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

build_colophon.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
import json
3-
import re
43
from datetime import datetime
54
import html
65
from pathlib import Path
@@ -14,11 +13,22 @@
1413

1514

1615
def format_commit_message(message):
17-
"""Format commit message with line breaks and linkified URLs."""
16+
"""Render commit message as HTML with Markdown support."""
17+
1818
escaped = html.escape(message)
19-
url_pattern = r"(https?://[^\s]+)"
20-
linkified = re.sub(url_pattern, r'<a href="\1">\1</a>', escaped)
21-
return linkified.replace("\n", "<br>")
19+
extensions = ["extra", "sane_lists", "nl2br"]
20+
21+
try:
22+
md = markdown.Markdown(
23+
extensions=extensions + ["linkify"],
24+
output_format="html5",
25+
)
26+
except ModuleNotFoundError:
27+
md = markdown.Markdown(extensions=extensions, output_format="html5")
28+
29+
formatted = md.convert(escaped)
30+
md.reset()
31+
return formatted
2232

2333

2434
def build_colophon():
@@ -56,12 +66,12 @@ def get_most_recent_date(page_data):
5666
<link rel=\"stylesheet\" href=\"styles.css\">
5767
</head>
5868
<body>
69+
<header class=\"page-shell content-flow\">
70+
<h1>tools.mathspp.com colophon</h1>
71+
<p>The tools on <a href=\"https://tools.mathspp.com/\">tools.mathspp.com</a> were mostly built using AI-assisted programming. This page lists {tool_count} tools and their development history.</p>
72+
<p>This page lists the commit messages for each tool.</p>
73+
</header>
5974
<main class=\"page-shell content-flow\">
60-
<header class=\"content-flow\">
61-
<h1>tools.mathspp.com colophon</h1>
62-
<p>The tools on <a href=\"https://tools.mathspp.com/\">tools.mathspp.com</a> were mostly built using AI-assisted programming. This page lists {tool_count} tools and their development history.</p>
63-
<p>This page lists the commit messages for each tool.</p>
64-
</header>
6575
<section class=\"tool-list\">
6676
"""
6777

0 commit comments

Comments
 (0)