From 20ebc7fde46a38cf6f37bbf150835b5f11bdebe1 Mon Sep 17 00:00:00 2001 From: Demonstrandum Date: Thu, 6 Aug 2020 01:55:22 +0100 Subject: [PATCH] Added syntax highlighting. --- highlight | 10 ++++++++-- stagit.c | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/highlight b/highlight index cfcc452..8273a3b 100755 --- a/highlight +++ b/highlight @@ -5,7 +5,7 @@ from pygments import highlight from pygments.formatters import HtmlFormatter from pygments.lexers import guess_lexer, guess_lexer_for_filename -from sys import stdin +from sys import stdin, stderr filename = stdin.readline().strip() contents = stdin.read() @@ -25,9 +25,15 @@ if lexer is None: lexer = TextLexer FORMAT = HtmlFormatter( - lineos='table', + style='murphy', + cssclass='highlight', + linenos='table', lineanchors='loc', anchorlinenos=True) print(highlight(contents, lexer, FORMAT)) +print('') +print("Lexer: {}.".format(lexer), file=stderr) diff --git a/stagit.c b/stagit.c index 9a8ccd0..bb64869 100644 --- a/stagit.c +++ b/stagit.c @@ -397,12 +397,14 @@ writefooter(FILE *fp) int syntax_highlight(const char *filename, FILE *fp, const char *s, size_t len) { + // Flush HTML-file + fflush(fp); // Copy STDOUT int stdout_copy = dup(1); // Redirect STDOUT dup2(fileno(fp), 1); - // Ruby script for syntax highlighting. + // Python Pygments script for syntax highlighting. FILE *child = popen("./highlight", "w"); if (child == NULL) { printf("child is null: %s", strerror(errno)); @@ -419,6 +421,7 @@ syntax_highlight(const char *filename, FILE *fp, const char *s, size_t len) } pclose(child); + fflush(stdout); // Give back STDOUT. dup2(stdout_copy, 1); return lc; -- 2.39.2