List for cgit developers and users
 help / color / mirror / Atom feed
From: stefan at sevenbyte.org (Stefan Tatschner)
Subject: syntax-highlighting.py
Date: Mon, 04 Nov 2013 21:46:40 +0100	[thread overview]
Message-ID: <1383598000.2791.14.camel@localhost.localdomain> (raw)

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]:
https://github.com/statschner/cgit_stuff/blob/4f847ddcd5aa7de0948bdb6b200a966b6389d94a/cgit_pygments.py
[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: This is a digitally signed message part
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20131104/1fae4a14/attachment.asc>


             reply	other threads:[~2013-11-04 20:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 20:46 stefan [this message]
2014-01-08 14:56 ` RESEND: syntax-highlighting.py stefan
2014-01-08 15:14   ` Jason
     [not found]     ` <CAHmME9p-89eXYBW0V-nn32XNrkFadFHD6r==qDjf9Pwk+jDNPg@mail.gmail.com>
2014-01-10 13:07       ` stefan
2014-01-10 16:19         ` Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1383598000.2791.14.camel@localhost.localdomain \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).