From: Armaan Bhojwani Date: Wed, 7 Apr 2021 15:49:53 +0000 (-0400) Subject: Add "view raw" button to rendered files X-Git-Url: https://git.armaanb.net/?p=stagit.git;a=commitdiff_plain;h=5d313f14fa7af39bd08b0ea6655c0d12cbbe295f Add "view raw" button to rendered files Also "view rendered" for unrendered markdown files --- diff --git a/src/stagit.c b/src/stagit.c index 100f7be..00409e6 100644 --- a/src/stagit.c +++ b/src/stagit.c @@ -71,6 +71,7 @@ static char *readme; static long long nlogcommits = -1; /* < 0 indicates not used */ bool htmlized; /* true if markdoown converted to HTML */ +static char oldfilename[PATH_MAX]; /* filename of the last file */ /* cache */ static git_oid lastoid; @@ -426,7 +427,6 @@ call_chroma(const char *filename, FILE *fp, const char *s, size_t len) if (strcmp(get_ext(filename), "md") == 0) htmlized = true; #endif - #ifdef HAS_CHROMA if (!htmlized) { // Copy STDOUT @@ -848,7 +848,27 @@ writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t fi fputs("

", fp); xmlencode(fp, filename, strlen(filename)); fprintf(fp, " (%s)", convertbytes((int)filesize)); - fputs("


", fp); + +#ifdef HAS_CMARK + char newfpath[PATH_MAX]; + char newfilename[PATH_MAX]; + if (strcmp(get_ext(filename), "md") == 0) { + fprintf(fp, " View raw", filename); + strcpy(newfpath, fpath); + strcat(newfpath, "-raw"); + + strcpy(newfilename, filename); + strcat(newfilename, "-raw"); + strcpy(oldfilename, filename); + + /* NOTE: recurses */ + writeblob(obj, newfpath, newfilename, filesize); + } else if (strcmp(get_ext(filename), "md-raw" ) == 0) { + fprintf(fp, " View rendered", oldfilename); + } +#endif + + fputs(".


", fp); if (git_blob_is_binary((git_blob *)obj)) { fputs("

Binary file.

\n", fp); @@ -856,16 +876,6 @@ writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t fi writeblobhtml(filename, fp, (git_blob *)obj); if (ferror(fp)) err(1, "fwrite"); - else if (htmlized) { - /* NOTE: recurses */ - char newfpath[PATH_MAX]; - strcat(newfpath, fpath); - char newfilename[PATH_MAX]; - strcat(newfilename, filename); - writeblob(obj, strcat(newfpath, "-raw"), - strcat(newfilename, "-raw"), filesize); - // TODO: Add view-raw button - } } writefooter(fp);