From 99bb0dbc9c058d3737054e11e417b8715874c75c Mon Sep 17 00:00:00 2001 From: Patrick Date: Tue, 23 Dec 2025 23:56:13 +0100 Subject: only show preview/code links on markdown blobs --- ui-tree.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ui-tree.c b/ui-tree.c index 61049e7..897a92d 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -18,12 +18,11 @@ struct walk_tree_context { int state; }; -static void print_text_buffer(const char *name, char *buf, unsigned long size) +static void print_text_buffer(const char *name, char *buf, unsigned long size, bool is_markdown) { unsigned long lineno, idx; const char *numberfmt = "%1$d\n"; - bool is_markdown = (strncmp(".md", &name[strlen(name)-3], 3) == 0); if (is_markdown) { html("
"); } @@ -122,10 +121,14 @@ static void print_object(const struct object_id *oid, const char *path, const ch cgit_set_title_from_path(path); + bool is_markdown = (strncmp(".md", &basename[strlen(basename)-3], 3) == 0); + cgit_print_layout_start(); htmlf("blob: %s (", oid_to_hex(oid)); - html("preview) ("); - html("code) ("); + if (is_markdown) { + html("preview) ("); + html("code) ("); + } cgit_plain_link("plain", NULL, NULL, ctx.qry.head, rev, path); if (ctx.repo->enable_blame) { @@ -144,7 +147,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch if (buffer_is_binary(buf, size)) print_binary_buffer(buf, size); else - print_text_buffer(basename, buf, size); + print_text_buffer(basename, buf, size, is_markdown); free(buf); } -- cgit v1.2.3