From e56461626321209c816b2836b62b7d0d91d9eb96 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Wed, 15 Jul 2026 11:03:18 -1000 Subject: Add built-in syntax highlighting Highlighting previously required a source filter shelling out to something like Pygments. A configured source filter still takes precedence, every character is preserved so the line gutter stays aligned, and large files are skipped. --- source/ui-tree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source/ui-tree.c') diff --git a/source/ui-tree.c b/source/ui-tree.c index cbaca38..9181b1b 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -30,6 +30,7 @@ struct walk_tree_context { static void print_text_buffer(const char *name, char *buf, unsigned long size) { unsigned long lineno, idx; + const char *ext; const char *numberfmt = "%1$d\n"; html("\n"); @@ -64,7 +65,13 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size) return; } - html("
");
+	/* No source filter is configured, so tag the code with its file
+	 * extension (or bare name, for Makefile and the like) and let
+	 * cgit.js highlight it client-side. */
+	ext = strrchr(name, '.');
+	html("
");
 	html_txt(buf);
 	html("
\n"); } -- cgit v2.8.0