RESEND: syntax-highlighting.py

Stefan Tatschner stefan at sevenbyte.org
Wed Jan 8 15:56:20 CET 2014


Am 04.11.2013 21:46, schrieb Stefan Tatschner:
Hi there,
I created a python script for the syntax-highlighting thing in cgit
which solves a few problems with the shipped script in cgit [1]. I use
it in production since half a year.

- It uses python2 because there are still a lot of problems with
  python3 and pygments out there. [2], [3]
- I used guess_lexer_for_filename for a better detecting of the used
  languages (e.g. mixed HTML and PHP, HTML (Django)...).
  guess_lexer_for_filename does not work with python3 yet.
- The script looks whether there is a shebang line if it cannot
  determine the language.
- It maps cmakelists.txt and pkgbuild (arch linux package system) files
  to the correct lexer. Any other filenames can be added easily.
- The CSS has to be defined in the CSS file to avoid inline CSS.
- `sys.stdin.read().decode(encoding='utf-8', errors='ignore')` is used
  to ensure the functionality even for corrupted file encodings.

If you like my implementation I would be happy to create a patchfile. :)

Stefan

Links:
[1]:
http://cgit.sevenbyte.org/cgit_stuff/tree/cgit_pygments.py?id=4f847ddcd5aa7de0948bdb6b200a966b6389d94a
[2]:
https://bitbucket.org/birkenfeld/pygments-main/issue/901/problems-with-python3
[3]:
https://bitbucket.org/birkenfeld/pygments-main/issue/847/test-failures-with-python-33


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20140108/8f6e0a2b/attachment.asc>


More information about the CGit mailing list