]> git.armaanb.net Git - stagit.git/commitdiff
Switch to Chroma for syntax highlighting
authorArmaan Bhojwani <me@armaanb.net>
Mon, 5 Apr 2021 14:10:17 +0000 (10:10 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Mon, 5 Apr 2021 14:10:17 +0000 (10:10 -0400)
Makefile
requirements.txt [deleted file]
resources/syntax.css
src/highlight.py [deleted file]
src/stagit.c

index fbe5c86c5542e5c6482a2c5889dfa3e7a392a642..3a8dc8f5cbe3248510131b811bc640185489c0fb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -54,7 +54,7 @@ dist:
        rm -rf ${NAME}-${VERSION}
        mkdir -p ${NAME}-${VERSION}
        cp -f ${MAN1} ${HDR} ${SRC} ${COMPATSRC} ${DOC} \
-               Makefile resources/* src/highlight.py contrib/* \
+               Makefile resources/* contrib/* \
                ${NAME}-${VERSION}
        # make tarball
        tar -cf - ${NAME}-${VERSION} | \
@@ -63,8 +63,7 @@ dist:
 
 ${OBJ}: ${HDR}
 
-stagit: src/stagit.o ${COMPATOBJ} requirements.txt
-       pip3 install -r requirements.txt
+stagit: src/stagit.o ${COMPATOBJ}
        ${CC} -o $@ src/stagit.o ${COMPATOBJ} ${STAGIT_LDFLAGS}
 
 stagit-index: src/stagit-index.o ${COMPATOBJ}
@@ -86,7 +85,6 @@ install: all
                ${DESTDIR}${DOCPREFIX}
        mkdir -p ${DESTDIR}${SHAREPREFIX}
        cp -f resources/*\
-               src/highlight.py\
                ${DESTDIR}${SHAREPREFIX}
        # installing manual pages.
        mkdir -p ${DESTDIR}${MANPREFIX}/man1
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644 (file)
index 3d78ab3..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-Pygments
-markdown
-pymdown-extensions
index 4c774f608bd27ee04383044f7560bb195a1f9479..98664415962ba7a94bb434880450bdc9a09340cf 100644 (file)
@@ -1 +1 @@
-.highlight .hll{background-color:#ffc}.highlight{background:#282828;color:#ebdbb2;background-color:#282828}.highlight .c{color:#928374;font-style:italic;background-color:#282828}.highlight .err{color:#ebdbb2;background-color:#282828}.highlight .esc{color:#ebdbb2;background-color:#282828}.highlight .g{color:#ebdbb2;background-color:#282828}.highlight .k{color:#fe8019;background-color:#282828}.highlight .l{color:#ebdbb2;background-color:#282828}.highlight .n{color:#ebdbb2;background-color:#282828}.highlight .o{color:#fe8019;background-color:#282828}.highlight .x{color:#ebdbb2;background-color:#282828}.highlight .p{color:#ebdbb2;background-color:#282828}.highlight .ch{color:#928374;font-style:italic;background-color:#282828}.highlight .cm{color:#928374;font-style:italic;background-color:#282828}.highlight .cp{color:#8ec07c;background-color:#282828}.highlight .c1{color:#928374;font-style:italic;background-color:#282828}.highlight .cs{color:#928374;font-style:italic;background-color:#282828}.highlight .gd{color:#282828;background-color:#fb4934}.highlight .ge{color:#83a598;text-decoration:underline;background-color:#282828}.highlight .gr{color:#ebdbb2;font-weight:700;background-color:#fb4934}.highlight .gh{color:#b8bb26;font-weight:700;background-color:#282828}.highlight .gi{color:#282828;background-color:#b8bb26}.highlight .go{color:#504945;background-color:#282828}.highlight .gp{color:#ebdbb2;background-color:#282828}.highlight .gs{color:#ebdbb2;background-color:#282828}.highlight .gu{color:#b8bb26;font-weight:700;background-color:#282828}.highlight .gt{color:#ebdbb2;font-weight:700;background-color:#fb4934}.highlight .kc{color:#fe8019;background-color:#282828}.highlight .kd{color:#fe8019;background-color:#282828}.highlight .kn{color:#fe8019;background-color:#282828}.highlight .kp{color:#fe8019;background-color:#282828}.highlight .kr{color:#fe8019;background-color:#282828}.highlight .kt{color:#fabd2f;background-color:#282828}.highlight .ld{color:#ebdbb2;background-color:#282828}.highlight .m{color:#d3869b;background-color:#282828}.highlight .s{color:#b8bb26;background-color:#282828}.highlight .na{color:#b8bb26;font-weight:700;background-color:#282828}.highlight .nb{color:#fabd2f;background-color:#282828}.highlight .nc{color:#ebdbb2;background-color:#282828}.highlight .no{color:#d3869b;background-color:#282828}.highlight .nd{color:#ebdbb2;background-color:#282828}.highlight .ni{color:#fabd2f;background-color:#282828}.highlight .ne{color:#fb4934;background-color:#282828}.highlight .nf{color:#fabd2f;background-color:#282828}.highlight .nl{color:#fb4934;background-color:#282828}.highlight .nn{color:#ebdbb2;background-color:#282828}.highlight .nx{color:#ebdbb2;background-color:#282828}.highlight .py{color:#ebdbb2;background-color:#282828}.highlight .nt{color:#fb4934;background-color:#282828}.highlight .nv{color:#ebdbb2;background-color:#282828}.highlight .ow{color:#fe8019;background-color:#282828}.highlight .w{color:#ebdbb2;background-color:#282828}.highlight .mb{color:#d3869b;background-color:#282828}.highlight .mf{color:#d3869b;background-color:#282828}.highlight .mh{color:#d3869b;background-color:#282828}.highlight .mi{color:#d3869b;background-color:#282828}.highlight .mo{color:#d3869b;background-color:#282828}.highlight .sb{color:#b8bb26;background-color:#282828}.highlight .sc{color:#b8bb26;background-color:#282828}.highlight .sd{color:#b8bb26;background-color:#282828}.highlight .s2{color:#b8bb26;background-color:#282828}.highlight .se{color:#b8bb26;background-color:#282828}.highlight .sh{color:#b8bb26;background-color:#282828}.highlight .si{color:#b8bb26;background-color:#282828}.highlight .sx{color:#b8bb26;background-color:#282828}.highlight .sr{color:#b8bb26;background-color:#282828}.highlight .s1{color:#b8bb26;background-color:#282828}.highlight .ss{color:#83a598;background-color:#282828}.highlight .bp{color:#fabd2f;background-color:#282828}.highlight .vc{color:#ebdbb2;background-color:#282828}.highlight .vg{color:#ebdbb2;background-color:#282828}.highlight .vi{color:#ebdbb2;background-color:#282828}.highlight .il{color:#d3869b;background-color:#282828}
\ No newline at end of file
+.hll{background-color:#ffc}.highlight{background:#282828;color:#ebdbb2;background-color:#282828}.c{color:#928374;font-style:italic;background-color:#282828}.err{color:#ebdbb2;background-color:#282828}.esc{color:#ebdbb2;background-color:#282828}.g{color:#ebdbb2;background-color:#282828}.k{color:#fe8019;background-color:#282828}.l{color:#ebdbb2;background-color:#282828}.n{color:#ebdbb2;background-color:#282828}.o{color:#fe8019;background-color:#282828}.x{color:#ebdbb2;background-color:#282828}.p{color:#ebdbb2;background-color:#282828}.ch{color:#928374;font-style:italic;background-color:#282828}.cm{color:#928374;font-style:italic;background-color:#282828}.cp{color:#8ec07c;background-color:#282828}.c1{color:#928374;font-style:italic;background-color:#282828}.cs{color:#928374;font-style:italic;background-color:#282828}.gd{color:#282828;background-color:#fb4934}.ge{color:#83a598;text-decoration:underline;background-color:#282828}.gr{color:#ebdbb2;font-weight:700;background-color:#fb4934}.gh{color:#b8bb26;font-weight:700;background-color:#282828}.gi{color:#282828;background-color:#b8bb26}.go{color:#504945;background-color:#282828}.gp{color:#ebdbb2;background-color:#282828}.gs{color:#ebdbb2;background-color:#282828}.gu{color:#b8bb26;font-weight:700;background-color:#282828}.gt{color:#ebdbb2;font-weight:700;background-color:#fb4934}.kc{color:#fe8019;background-color:#282828}.kd{color:#fe8019;background-color:#282828}.kn{color:#fe8019;background-color:#282828}.kp{color:#fe8019;background-color:#282828}.kr{color:#fe8019;background-color:#282828}.kt{color:#fabd2f;background-color:#282828}.ld{color:#ebdbb2;background-color:#282828}.m{color:#d3869b;background-color:#282828}.s{color:#b8bb26;background-color:#282828}.na{color:#b8bb26;font-weight:700;background-color:#282828}.nb{color:#fabd2f;background-color:#282828}.nc{color:#ebdbb2;background-color:#282828}.no{color:#d3869b;background-color:#282828}.nd{color:#ebdbb2;background-color:#282828}.ni{color:#fabd2f;background-color:#282828}.ne{color:#fb4934;background-color:#282828}.nf{color:#fabd2f;background-color:#282828}.nl{color:#fb4934;background-color:#282828}.nn{color:#ebdbb2;background-color:#282828}.nx{color:#ebdbb2;background-color:#282828}.py{color:#ebdbb2;background-color:#282828}.nt{color:#fb4934;background-color:#282828}.nv{color:#ebdbb2;background-color:#282828}.ow{color:#fe8019;background-color:#282828}.w{color:#ebdbb2;background-color:#282828}.mb{color:#d3869b;background-color:#282828}.mf{color:#d3869b;background-color:#282828}.mh{color:#d3869b;background-color:#282828}.mi{color:#d3869b;background-color:#282828}.mo{color:#d3869b;background-color:#282828}.sb{color:#b8bb26;background-color:#282828}.sc{color:#b8bb26;background-color:#282828}.sd{color:#b8bb26;background-color:#282828}.s2{color:#b8bb26;background-color:#282828}.se{color:#b8bb26;background-color:#282828}.sh{color:#b8bb26;background-color:#282828}.si{color:#b8bb26;background-color:#282828}.sx{color:#b8bb26;background-color:#282828}.sr{color:#b8bb26;background-color:#282828}.s1{color:#b8bb26;background-color:#282828}.ss{color:#83a598;background-color:#282828}.bp{color:#fabd2f;background-color:#282828}.vc{color:#ebdbb2;background-color:#282828}.vg{color:#ebdbb2;background-color:#282828}.vi{color:#ebdbb2;background-color:#282828}.il{color:#d3869b;background-color:#282828}
diff --git a/src/highlight.py b/src/highlight.py
deleted file mode 100755 (executable)
index 2b81d8c..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python3
-
-import pygments
-from pygments import highlight
-from pygments.formatters import HtmlFormatter
-import pygments.lexers
-from markdown import markdown
-
-from sys import stdin, stderr
-
-filename = stdin.readline().strip()
-contents = stdin.read()
-lexer = None
-
-try:
-    lexer = pygments.lexers.guess_lexer_for_filename(filename, contents)
-except pygments.util.ClassNotFound:
-    try:
-        lexer = pygments.lexers.guess_lexer(contents)
-    except pygments.util.ClassNotFound:
-        pass
-
-if lexer is None:
-    lexer = pygments.lexers.special.TextLexer
-
-rendered = (
-    markdown(
-        contents,
-        extensions=[
-            "codehilite",
-            "extra",
-            "sane_lists",
-            "smarty",
-            "pymdownx.tasklist",
-        ],
-    )
-    if lexer.__class__ is pygments.lexers.MarkdownLexer
-    else None
-)
-
-formatter = HtmlFormatter(
-    style="monokai",
-    cssclass="highlight",
-    linenos="table",
-    lineanchors="loc",
-    anchorlinenos=True,
-)
-
-outp = ""
-if rendered:
-    outp += '<article class="markup markdown">'
-    outp += rendered
-    outp += "</article>"
-outp += f'<div id="blob">{highlight(contents, lexer, formatter)}</div>"'
-outp += '<link rel="stylesheet" href="/syntax.css"'
-
-print(outp)
-
-print(f"Filename: {filename}; Lexer: {lexer}.", file=stderr)
-
-if rendered:
-    print("Markdown was rendered in addition.", file=stderr)
index aa99c7767eff014f68b0ec0477f6e1ac94b83a4c..6ffcea52cdbe0b730d7b363e4da01b2e740cf053 100644 (file)
@@ -397,7 +397,7 @@ writefooter(FILE *fp)
 }
 
 int
-call_py(const char *filename, FILE *fp, const char *s, size_t len)
+call_chroma(const char *filename, FILE *fp, const char *s, size_t len)
 {
        // Flush HTML-file
        fflush(fp);
@@ -406,8 +406,10 @@ call_py(const char *filename, FILE *fp, const char *s, size_t len)
        // Redirect STDOUT
        dup2(fileno(fp), 1);
 
-       // Python Pygments script for syntax highlighting.
-       FILE *child = popen("/usr/local/share/stagit/highlight.py", "w");
+       char cmd[] = "chroma --html --html-only --html-lines --html-lines-table --filename ";
+       strcat(cmd, filename);
+
+       FILE *child = popen(cmd, "w");
        if (child == NULL) {
                printf("child is null: %s", strerror(errno));
                exit(1);
@@ -429,7 +431,7 @@ call_py(const char *filename, FILE *fp, const char *s, size_t len)
        return lc;
 }
 
-int
+       int
 writeblobhtml(const char *filename, FILE *fp, const git_blob *blob)
 {
        int lc = 0;
@@ -437,21 +439,21 @@ writeblobhtml(const char *filename, FILE *fp, const git_blob *blob)
        git_off_t len = git_blob_rawsize(blob);
 
        if (len > 0) {
-               lc = call_py(filename, fp, s, len);
+               lc = call_chroma(filename, fp, s, len);
        }
 
        return lc;
 }
 
-void
+       void
 printcommit(FILE *fp, struct commitinfo *ci)
 {
        fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n",
-               relpath, ci->oid, ci->oid);
+                       relpath, ci->oid, ci->oid);
 
        if (ci->parentoid[0])
                fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n",
-                       relpath, ci->parentoid, ci->parentoid);
+                               relpath, ci->parentoid, ci->parentoid);
 
        if (ci->author) {
                fputs("<b>Author:</b> ", fp);
@@ -471,7 +473,7 @@ printcommit(FILE *fp, struct commitinfo *ci)
        }
 }
 
-void
+       void
 printshowfile(FILE *fp, struct commitinfo *ci)
 {
        const git_diff_delta *delta;