codeview

A light and fast web based git repository viewer

Log | Files | Refs | README | LICENSE

commit e97335a008ca8f7bedac17f2404961a8df7b7465
parent 1219ab97fb88af70d45722cfa4e6cb4ad1dcd7c7
Author: Abdul Rahim <abdul.rahim@myyahoo.com>
Date:   Tue,  1 Oct 2024 01:30:21 +0530

perfect, now the code highlighting will work with auto detection of file

Diffstat:
Mget_lang.c | 1-
Mstagit.c | 32++++++++++++++++----------------
2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/get_lang.c b/get_lang.c @@ -18,7 +18,6 @@ char* to_lower(const char *upper) str[i] = tolower(upper[i]); } str[i] = '\0'; - printf("lowercased: %s\n", str); return str; } diff --git a/stagit.c b/stagit.c @@ -15,7 +15,7 @@ #include <git2.h> #include "compat.h" -//#include "get_lang.h" +#include "get_lang.h" #define LEN(s) (sizeof(s)/sizeof(*s)) @@ -597,25 +597,25 @@ size_t writeblobhtml(FILE *fp, const git_blob *blob, const char* filename) { size_t n = 0, i, len, prev; - const char *nfmt = "<a href=\"#l%zu\" class=\"line\" id=\"l%zu\">%7zu</a><code> "; //removed <code> here + const char *nfmt_old = "<a href=\"#l%zu\" class=\"line\" id=\"l%zu\">%7zu</a>"; //removed <code> here const char *s = git_blob_rawcontent(blob); len = git_blob_rawsize(blob); fputs("<pre id=\"blob\">\n", fp); -// -// char *code_opening = (char *) malloc( 235 ); -// if (!code_opening) -// return -2; -// - // TODO the language should contain the actual language - // implemented via get_lang() from get_lang.h - //char *this_lang = get_lang(filename); - //printf("filename: %s\n", filename); - - //sprintf(code_opening, "<code class=\"language-%s\"> ", this_lang); - //char *nfmt = (char *) malloc( strlen(nfmt_old) + strlen(code_opening) + 1); - //strcpy(nfmt, nfmt_old); - //strcat(nfmt, code_opening); + + char code_opening[250]; + + char this_lang[200]; + const char *ret = get_lang(filename); + if (!ret) + strcpy(this_lang, "plaintext"); + else + strcpy(this_lang, ret); + + sprintf(code_opening, "<code class=\"language-%s\"> ", this_lang); + char *nfmt = (char *) malloc( strlen(nfmt_old) + strlen(code_opening) + 1); + strcpy(nfmt, nfmt_old); + strcat(nfmt, code_opening); if (len > 0) { for (i = 0, prev = 0; i < len; i++) {