diff options
author | Cullum Smith <cullum@sacredheartsc.com> | 2024-11-12 23:50:18 -0500 |
---|---|---|
committer | Cullum Smith <cullum@sacredheartsc.com> | 2024-11-12 23:50:18 -0500 |
commit | 5aa2283f9951b3e035824b54bd0277ebf4394ffa (patch) | |
tree | df93cef70ce1d49576b9a98f165e8dfc6aaa52f7 /files/usr/local/lib/cgit | |
parent | 6512242bc03acf2bdaa4fea6fcc7fe51c2330f03 (diff) | |
download | infrastructure-5aa2283f9951b3e035824b54bd0277ebf4394ffa.tar.gz |
add gitolite/cgit
Diffstat (limited to 'files/usr/local/lib/cgit')
-rw-r--r-- | files/usr/local/lib/cgit/filters/syntax-highlighting-custom.py.git_server | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/files/usr/local/lib/cgit/filters/syntax-highlighting-custom.py.git_server b/files/usr/local/lib/cgit/filters/syntax-highlighting-custom.py.git_server new file mode 100644 index 0000000..1d71275 --- /dev/null +++ b/files/usr/local/lib/cgit/filters/syntax-highlighting-custom.py.git_server @@ -0,0 +1,34 @@ +#!/usr/local/bin/python + +import sys +import io +from pygments import highlight +from pygments.util import ClassNotFound +from pygments.lexers import TextLexer +from pygments.lexers import guess_lexer +from pygments.lexers import guess_lexer_for_filename +from pygments.formatters import HtmlFormatter + +sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace') +sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') +data = sys.stdin.read() +filename = sys.argv[1] +formatter = HtmlFormatter(style='${cgit_pygments_style}', nobackground=True) + +try: + lexer = guess_lexer_for_filename(filename, data) +except ClassNotFound: + # check if there is any shebang + if data[0:2] == '#!': + lexer = guess_lexer(data) + else: + lexer = TextLexer() +except TypeError: + lexer = TextLexer() + +# highlight! :-) +# printout pygments' css definitions as well +sys.stdout.write('<style>') +sys.stdout.write(formatter.get_style_defs('.highlight')) +sys.stdout.write('</style>') +sys.stdout.write(highlight(data, lexer, formatter, outfile=None)) |