From 17e60837f192a683044b8f54fc225ee24f0b7af5 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Sat, 6 Mar 2021 18:22:28 -0500 Subject: [PATCH] First commit Lots of cleanup and playing around with things --- .gitignore | 4 ++- Makefile | 14 +++++---- highlight | 58 -------------------------------------- highlight.py | 61 ++++++++++++++++++++++++++++++++++++++++ stagit.c | 5 +++- style.css | 78 +++++++++++++++++++++++++-------------------------- style.min.css | 1 + syntax.css | 1 + 8 files changed, 117 insertions(+), 105 deletions(-) delete mode 100755 highlight create mode 100755 highlight.py create mode 100644 style.min.css create mode 100644 syntax.css diff --git a/.gitignore b/.gitignore index 89d4bc8..e6ec977 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ # Generated files *.o *.so -*.out +stagit +stagit-index +html diff --git a/Makefile b/Makefile index f94e8e9..1effc07 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,8 @@ COMPATSRC = \ strlcat.c\ strlcpy.c BIN = \ - stagit.out\ - stagit-index.out + stagit\ + stagit-index MAN1 = \ stagit.1\ stagit-index.1 @@ -53,7 +53,7 @@ dist: rm -rf ${NAME}-${VERSION} mkdir -p ${NAME}-${VERSION} cp -f ${MAN1} ${HDR} ${SRC} ${COMPATSRC} ${DOC} \ - Makefile favicon.png logo.png style.css \ + Makefile favicon.png logo.png style.css syntax.css highlight.py \ example_create.sh example_post-receive.sh \ ${NAME}-${VERSION} # make tarball @@ -63,11 +63,11 @@ dist: ${OBJ}: ${HDR} -stagit.out: stagit.o ${COMPATOBJ} requirements.txt +stagit: stagit.o ${COMPATOBJ} requirements.txt pip3 install -r requirements.txt ${CC} -o $@ stagit.o ${COMPATOBJ} ${STAGIT_LDFLAGS} -stagit-index.out: stagit-index.o ${COMPATOBJ} +stagit-index: stagit-index.o ${COMPATOBJ} ${CC} -o $@ stagit-index.o ${COMPATOBJ} ${STAGIT_LDFLAGS} clean: @@ -81,11 +81,13 @@ install: all # installing example files. mkdir -p ${DESTDIR}${DOCPREFIX} cp -f style.css\ + syntax.css\ favicon.png\ logo.png\ example_create.sh\ example_post-receive.sh\ README\ + highlight.py\ ${DESTDIR}${DOCPREFIX} # installing manual pages. mkdir -p ${DESTDIR}${MANPREFIX}/man1 @@ -98,6 +100,8 @@ uninstall: # removing example files. rm -f \ ${DESTDIR}${DOCPREFIX}/style.css\ + ${DESTDIR}${DOCPREFIX}/syntax.css\ + ${DESTDIR}${DOCPREFIX}/highlight.py\ ${DESTDIR}${DOCPREFIX}/favicon.png\ ${DESTDIR}${DOCPREFIX}/logo.png\ ${DESTDIR}${DOCPREFIX}/example_create.sh\ diff --git a/highlight b/highlight deleted file mode 100755 index 61f554f..0000000 --- a/highlight +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 - -import pygments -from pygments import highlight -from pygments.formatters import HtmlFormatter -from pygments.lexers import guess_lexer, guess_lexer_for_filename - -from sys import stdin, stderr - -filename = stdin.readline().strip() -contents = stdin.read() - -lexer=None - -try: - lexer = guess_lexer_for_filename(filename, contents) -except pygments.util.ClassNotFound: - try: - lexer = guess_lexer(contents) - except pygments.util.ClassNotFound: - pass - -if lexer is None: - from pygments.lexers import TextLexer - lexer = TextLexer() - -rendered = None -if lexer.__class__ is pygments.lexers.MarkdownLexer: - from markdown import markdown - rendered = markdown(contents, extensions=[ - 'codehilite', - 'extra', - 'sane_lists', - 'smarty', - 'pymdownx.tasklist' - ]) - -FORMAT = HtmlFormatter( - style='murphy', - cssclass='highlight', - linenos='table', - lineanchors='loc', - anchorlinenos=True) - -if rendered: - print('
') - print(rendered) - print('
') -print('
') -print(highlight(contents, lexer, FORMAT)) -print('
') -print('') - -print("Filename: {}; Lexer: {}.".format(filename, lexer), file=stderr) -if rendered: - print("Markdown was rendered in addition.", file=stderr) diff --git a/highlight.py b/highlight.py new file mode 100755 index 0000000..eb146e7 --- /dev/null +++ b/highlight.py @@ -0,0 +1,61 @@ +#!/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, +) + +if rendered: + print('
') + print(rendered) + print("
") +print('
') +print(highlight(contents, lexer, formatter)) +print("
") +print('\n", name, relpath); fprintf(fp, "\n", relpath); + fprintf(fp, "\n", relpath); fputs("\n\n
", fp); fprintf(fp, "\"\"", relpath, relpath); @@ -405,7 +406,7 @@ syntax_highlight(const char *filename, FILE *fp, const char *s, size_t len) dup2(fileno(fp), 1); // Python Pygments script for syntax highlighting. - FILE *child = popen("./highlight", "w"); + FILE *child = popen("/usr/local/share/doc/stagit/highlight.py", "w"); if (child == NULL) { printf("child is null: %s", strerror(errno)); exit(1); @@ -1258,6 +1259,8 @@ main(int argc, char *argv[]) writefiles(fp, head); writefooter(fp); fclose(fp); + system("cp /usr/local/share/doc/stagit/style.css ."); + system("cp /usr/local/share/doc/stagit/syntax.css ."); /* summary page with branches and tags */ fp = efopen("refs.html", "w"); diff --git a/style.css b/style.css index 20ce206..af0d598 100644 --- a/style.css +++ b/style.css @@ -1,21 +1,17 @@ -html { - font-size: 12px; - height: 100%; -} - body { - margin: 5rem auto; - color: #222; - background-color: #fff; + font-size: 0.8rem; font-family: monospace; - width: 66rem; + color: #ebdbb2; + background-color: #282828; + max-width: max-content; + min-width: min-content; } -pre { -moz-tab-size: 4; } -pre { tab-size: 4; } +pre { + tab-size: 4; +} h1, h2, h3, h4, h5, h6 { - font-size: 1em; margin: 0; } @@ -28,7 +24,7 @@ img { } a:target { - background-color: #ccc; + background-color: #eee; } a.d, @@ -39,26 +35,25 @@ a.line { } #blob { - display: block; - max-width: 100%; - overflow-x: scroll; + display: block; + max-width: 100%; } article.markup { font-size: 15px; - border: 2px solid #00000017; - border-radius: 10px; - font-family: sans-serif; - padding: 2.5em; - margin: 2em 0; + border: 2px solid #eee; + border-radius: 10px; + font-family: sans-serif; + padding: 2.5em; + margin: 2em 0; } article.markup code { - font-size: 0.9em; - border: 1px solid #dbdbdb; - background-color: #f7f7f7; - padding: 0 0.3em; - border-radius: 0.3em + font-size: 0.9em; + border: 1px solid #dbdbdb; + background-color: #f7f7f7; + padding: 0 0.3em; + border-radius: 0.3em } article.markup pre code { @@ -88,19 +83,19 @@ article.markup h2 { } article.markup h3 { - font-size: 1.5em; + font-size: 1.5em; } article.markup h4 { - font-size: 1.3em; + font-size: 1.3em; } article.markup h5 { - font-size: 1.1em; + font-size: 1.1em; } article.markup h6 { - font-size: 1em; + font-size: 1em; } article img { @@ -124,10 +119,14 @@ article img { } #blob a:hover { - color: blue; + color: #eee; text-decoration: none; } +a { + color: #83a598; +} + table thead td { font-weight: bold; } @@ -146,7 +145,7 @@ table td { #index tr:hover td, #log tr:hover td, #files tr:hover td { - background-color: #eee; + background-color: #333; } #index tr td:nth-child(2), @@ -161,12 +160,12 @@ td.num { } .desc { - color: #777; + color: #928374; } hr { border: 0; - border-top: 1px solid #777; + border-top: 1px solid #928374; height: 1px; } @@ -175,19 +174,19 @@ pre { } pre a.h { - color: #00a; + color: #fe8019; } .A, span.i, pre a.i { - color: #070; + color: #b8bb26; } .D, span.d, pre a.d { - color: #e00; + color: #fb4934; } pre a.h:hover, @@ -203,11 +202,10 @@ pre a.d:hover { .url td:nth-child(2) span { padding: 1px 5px; - background-color: #eee; - border: 1px solid #ddd; + border: 1px solid #ebdbb2; border-radius: 5px; } .url td:nth-child(2) span a { - color: #444; + color: #ebdbb2; } diff --git a/style.min.css b/style.min.css new file mode 100644 index 0000000..063054a --- /dev/null +++ b/style.min.css @@ -0,0 +1 @@ +body{font-size:.8rem;font-family:monospace;color:#ebdbb2;background-color:#282828;max-width:max-content;min-width:min-content}pre{tab-size:4}h1,h2,h3,h4,h5,h6{margin:0}img,h1,h2{vertical-align:middle}img{border:0}a:target{background-color:#eee}a.d,a.h,a.i,a.line{text-decoration:none}#blob{display:block;max-width:100%}article.markup{font-size:15px;border:2px solid #eee;border-radius:10px;font-family:sans-serif;padding:2.5em;margin:2em 0}article.markup code{font-size:.9em;border:1px solid #dbdbdb;background-color:#f7f7f7;padding:0 .3em;border-radius:.3em}article.markup pre code{border:none;background:0 0;padding:0;border-radius:0}article.markup pre{background-color:#f7f7f7;padding:1em;border:1px solid #dbdbdb;border-radius:.3em}article.markup h1{font-size:2.4em;padding-bottom:6px;border-bottom:5px solid #0000000a}article.markup h2{font-size:1.9em;padding-bottom:5px;border-bottom:2px solid #00000014}article.markup h3{font-size:1.5em}article.markup h4{font-size:1.3em}article.markup h5{font-size:1.1em}article.markup h6{font-size:1em}article img{max-width:100%}.linenos{margin-right:0;border-right:1px solid rgb(0 0 0/8%);user-select:none}.linenos a{margin-right:.9em;user-select:none;text-decoration:none}#blob a{color:#777}#blob a:hover{color:#eee;text-decoration:none}a{color:#83a598}table thead td{font-weight:700}table td{padding:0 .4em}#content table td{vertical-align:top;white-space:nowrap}#branches tr:hover td,#tags tr:hover td,#index tr:hover td,#log tr:hover td,#files tr:hover td{background-color:#333}#index tr td:nth-child(2),#tags tr td:nth-child(3),#branches tr td:nth-child(3),#log tr td:nth-child(2){white-space:normal}td.num{text-align:right}.desc{color:#928374}hr{border:0;border-top:1px solid #928374;height:1px}pre{font-family:monospace}pre a.h{color:#fe8019}.A,span.i,pre a.i{color:#b8bb26}.D,span.d,pre a.d{color:#fb4934}pre a.h:hover,pre a.i:hover,pre a.d:hover{text-decoration:none}.url td:nth-child(2){padding-top:.2em;padding-bottom:.9em}.url td:nth-child(2) span{padding:1px 5px;border:1px solid #ebdbb2;border-radius:5px}.url td:nth-child(2) span a{color:#ebdbb2} \ No newline at end of file diff --git a/syntax.css b/syntax.css new file mode 100644 index 0000000..4c774f6 --- /dev/null +++ b/syntax.css @@ -0,0 +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 -- 2.39.2