#include <unistd.h>
#include <git2.h>
+
+#ifdef HAS_CMARK
#include <cmark-gfm.h>
+#endif
#include "cp.h"
#include "compat.h"
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);
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));
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);
} else {
fprintf(fp, "%s", html);
}
+#else
+ fprintf(fp, "<pre>%s</pre>", s);
+#endif
}
void
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)) {
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);