The syntax highlighting option in a cgit installation is no working properly and I want to see if it will run properly from the command line if all the necessary parameters are present.
The option in /etc/cgitrc
is correctly set.
source-filter=/usr/lib/cgit/filters/syntax-highlighting.sh
When I ran the highlight
command on a bash file for instance the css and span classes are in the output, but when I run /usr/lib/cgit/filters/syntax-highlighting.sh on the file the css and span tags don't show.
The command actual highlight
command in the script (the last line) is
exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null
#!/bin/sh
# This script can be used to implement syntax highlighting in the cgit
# tree-view by refering to this file with the source-filter or repo.source-
# filter options in cgitrc.
#
# This script requires a shell supporting the ${var##pattern} syntax.
# It is supported by at least dash and bash, however busybox environments
# might have to use an external call to sed instead.
#
# Code considered irrelevant snipped
#
# store filename and extension in local vars
BASENAME="$1"
EXTENSION="${BASENAME##*.}"
[ "${BASENAME}" = "${EXTENSION}" ] && EXTENSION=txt
[ -z "${EXTENSION}" ] && EXTENSION=txt
# map Makefile and Makefile.* to .mk
[ "${BASENAME%%.*}" = "Makefile" ] && EXTENSION=mk
# highlight versions 2 and 3 have different commandline options. Specifically,
# the -X option that is used for version 2 is replaced by the -O xhtml option
# for version 3.
#
# Version 2 can be found (for example) on EPEL 5, while version 3 can be
# found (for example) on EPEL 6.
#
# 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
Best Answer
It turns out that in order to get syntax highlighting working under cgit, the line specifying syntax highlighting must appear before the line for the repo locations. In the example given below, syntax highlighting will fail if the
source-filter
line is placed after theinclude
line.I checked and unless it is documented somewhere it must be a bug. Perhaps some design issue requires to be that way.
More info at https://wiki.archlinux.org/index.php/Cgit