mainSavannah Administration - Support: sr #110279, Request: syntax highlighting in...


sr #110279: Request: syntax highlighting in cgit web interface

Submitter:  Eric Bavier <bavier>
Submitted:  Thu 23 Jul 2020 03:31:08 AM UTC
Category:  Source code repositories - web browsing Priority:  5 - Normal
Severity:  1 - Wish Status:  Done
Privacy:  Public Assigned to:  bandali
Operating System:  None Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup

Fri 19 May 2023 08:11:00 PM UTC, comment #4: 
Ineiev <ineiev>
Site Administrator
Sun 06 Sep 2020 02:54:30 AM UTC, comment #3: 

From past experience with cgit on my personal server, adding the
python-pygements-based highlighter adds a quite noticeable delay to the
load time of source view of all files, possibly due it being written in
Python, which is not exactly known for its speed.

The highlight-based highlighter, on the other hand, did not add any
noticeable amount of time to the page loads of source views on that
server of mine.

I will experiment with the highlighters for Savannah cgit and see if we
could feasibly use one of them, considering that Savannah has a much
larger and more regular viewing audience (i.e. greater system load)
compared to my personal server).

Amin Bandali <bandali>
Site Administrator
Sun 06 Sep 2020 02:24:27 AM UTC, comment #2: 


Probably we should consider client-side syntax highlighting as well.

Doing it on the server-side will increase load. Though I'm not sure about impact and weather its acceptable or not.

Anatoly A. Kazantsev <jimcrow>
Thu 23 Jul 2020 05:12:58 AM UTC, comment #1: 

Hi all,

This seems doable, there is a howto with two options. To me it seems option 1 is preferred. Please see quote below:

"Cgit supports syntax highlighting when viewing blobs. To enable syntax highlighting, you have several options.

Option 1. Using python-pygments

Install python-pygments and add the filter in /etc/cgitrc


To change the coloring style, modify the style argument that is passed to HtmlFormatter in the file. For instance, to change the coloring style to 'tango':

 formatter = HtmlFormatter(encoding='utf-8', style='tango')

To get a list of all coloring styles that are available, do:

 $ python
 >>> from pygments.styles import get_all_styles
 >>> list(get_all_styles())
 ['manni', 'igor', 'xcode', 'vim', 'autumn', 'vs', 'rrt', 'native', 'perldoc', 'borland', 'tango', 'emacs', 'friendly', 'monokai', 'paraiso-dark', 'colorful', 'murphy', 'bw', 'pastie', 'paraiso-light', 'trac', 'default', 'fruity']

Option 2. Using highlight

Install the highlight package.

Copy /usr/lib/cgit/filters/ to /usr/lib/cgit/filters/ Then, in the copied file, comment out version 2 and comment in version 3. You may want to add --inline-css to the options of highlight for a more colorful output without editing cgit's css file.

 # This is for version 2
 #exec highlight --force -f -I -X -S "$EXTENSION" 2>/dev/null
 # This is for version 3
 exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null

Enable the filter in /etc/cgitrc


Note: Editing /usr/lib/cgit/filters/ directly would lose all the modifications as soon as cgit is updated."

Licence: Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.

Svetlana T <svetlana>
Site Administrator
Thu 23 Jul 2020 03:31:08 AM UTC, original submission:  

I was wondering if we could enable syntax highlighting in cgit's web interface when browsing source files?  From my little bit of research, it seems cgit can use python-pygments or the "highlight" utility with only a small amount of configuration needed.

Please consider.  I think this would make the browsing experience much nicer.

Eric Bavier <bavier>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by ineiev (Posted a comment)
  • -email is unavailable- added by bandali (Posted a comment)
  • -email is unavailable- added by jimcrow (Posted a comment)
  • -email is unavailable- added by svetlana (Posted a comment)
  • -email is unavailable- added by bavier (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-05-19 ineiev StatusNone Done
        Open/ClosedOpen Closed
    2020-09-06 bandali Assigned toNone bandali

    Back to the top

    Powered by Savane 3.13-3cd0.
    Corresponding source code