From 5f11eee7396ba2edecf099582f413ba46e6e47f8 Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Sun, 25 Feb 2024 08:01:32 +0000 Subject: cgit better highlight --- usr/lib/cgit/filters/syntax-highlighting-edited.sh | 27 ++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'usr') diff --git a/usr/lib/cgit/filters/syntax-highlighting-edited.sh b/usr/lib/cgit/filters/syntax-highlighting-edited.sh index 3de95fa5..2c33b907 100755 --- a/usr/lib/cgit/filters/syntax-highlighting-edited.sh +++ b/usr/lib/cgit/filters/syntax-highlighting-edited.sh @@ -101,21 +101,14 @@ BASENAME="$1" EXTENSION="${BASENAME##*.}" -[ "${BASENAME}" = "${EXTENSION}" ] && EXTENSION=txt -[ -z "${EXTENSION}" ] && EXTENSION=txt +# map Makefile, Makefile.*, makefile, and makefile.* to .mk +if [ "${BASENAME%%.*}" = Makefile ] || [ "${BASENAME%%.*}" = makefile ]; then + EXTENSION=mk +fi -# 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 +# `--force` needed for highlight; one example is `cat textfile | highlight -O ansi --force`, without `--force` will error 1 and no output +if [ "${BASENAME}" = "${EXTENSION}" ] || [ -z "${EXTENSION}" ]; then + exec highlight --force --inline-css -f -I -O xhtml 2>/dev/null +else + exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null +fi -- cgit v1.2.3-70-g09d2