diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
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.
Diffstat (limited to 'source/ui-tree.c')
| -rw-r--r-- | source/ui-tree.c | 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 8 insertions, 1 deletion
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 = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n"; html("<table summary='blob content' class='blob'>\n"); @@ -64,7 +65,13 @@ static void print_text_buffer(const char *name, char *buf, unsigned long size) return; } - html("<td class='lines'><pre><code>"); + /* 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("<td class='lines'><pre><code data-lang='"); + html_attr(ext && ext[1] ? ext + 1 : name); + html("'>"); html_txt(buf); html("</code></pre></td></tr></table>\n"); } |
