]> git.armaanb.net Git - stagit.git/blobdiff - src/stagit.c
Generate raw file if htmlized
[stagit.git] / src / stagit.c
index b5580b8cc772f7bebd6533cd437d0aae98ef6766..b71eeda0db64c440eceda86eb7940ded010f574f 100644 (file)
 #include <unistd.h>
 
 #include <git2.h>
+
+#ifdef HAS_CMARK
 #include <cmark-gfm.h>
+#endif
 
 #include "cp.h"
 #include "compat.h"
@@ -347,7 +350,7 @@ void
 writeheader(FILE *fp, const char *title)
 {
        fputs("<!DOCTYPE html>\n"
-               "<html>\n<head>\n"
+               "<html lang=\"en\">\n<head>\n"
                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
                "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n"
                "<title>", fp);
@@ -364,7 +367,7 @@ writeheader(FILE *fp, const char *title)
        fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath);
        fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%ssyntax.css\" />\n", relpath);
        fputs("</head>\n<body>\n<table><tr><td>", fp);
-       fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
+       fprintf(fp, "<a href=\"../%s\"><img alt=\"Home\" src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
                relpath, relpath);
        fputs("</td><td><h1>", fp);
        xmlencode(fp, strippedname, strlen(strippedname));
@@ -414,12 +417,17 @@ void
 call_chroma(const char *filename, FILE *fp, const char *s, size_t len)
 {
        htmlized = false;
+       char *html = "";
        // Flush HTML-file
        fflush(fp);
 
-       char *html = cmark_markdown_to_html(s, len, CMARK_OPT_DEFAULT);
+#ifdef HAS_CMARK
+       html = cmark_markdown_to_html(s, len, CMARK_OPT_DEFAULT);
        if (strcmp(get_ext(filename), "md") == 0) htmlized = true;
+#endif
+
 
+#ifdef HAS_CHROMA
        if (!htmlized) {
                // Copy STDOUT
                int stdout_copy = dup(1);
@@ -450,6 +458,9 @@ call_chroma(const char *filename, FILE *fp, const char *s, size_t len)
        } else {
                fprintf(fp, "%s", html);
        }
+#else
+               fprintf(fp, "<pre>%s</pre>", s);
+#endif
 }
 
 void
@@ -837,7 +848,6 @@ writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t fi
        fputs("<p> ", fp);
        xmlencode(fp, filename, strlen(filename));
        fprintf(fp, " (%s)", convertbytes((int)filesize));
-
        fputs("</p><hr/>", fp);
 
        if (git_blob_is_binary((git_blob *)obj)) {
@@ -846,6 +856,15 @@ 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);