From c5c96be29effb246cca890bc342fbc207da34dfe Mon Sep 17 00:00:00 2001 From: Xiao Pan Date: Sun, 25 Feb 2024 09:25:54 +0000 Subject: highlight use --syntax-by-name to simplify code --- usr/lib/cgit/filters/syntax-highlighting-edited.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'usr/lib') diff --git a/usr/lib/cgit/filters/syntax-highlighting-edited.sh b/usr/lib/cgit/filters/syntax-highlighting-edited.sh index 81e39197..3fe4ab41 100755 --- a/usr/lib/cgit/filters/syntax-highlighting-edited.sh +++ b/usr/lib/cgit/filters/syntax-highlighting-edited.sh @@ -97,18 +97,17 @@ # CGIT_REPO_CLONE_URL ( = repo.clone-url setting ) # -# store filename and extension in local vars -BASENAME="$1" -EXTENSION="${BASENAME##*.}" - -# map Makefile, Makefile.*, makefile, and makefile.* to .mk -if [ "${BASENAME%%.*}" = Makefile ] || [ "${BASENAME%%.*}" = makefile ]; then - EXTENSION=mk -fi +syntax= +case "$1" in + nginx.conf) syntax=nginx;; + pacman.conf) syntax=ini;; + cgitrc) syntax=ini;; + .gitolite.rc) syntax=perl;; +esac # `--force` needed for highlight; one example is `< 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 +if [ "$syntax_type" ]; then + exec highlight --force --inline-css -f -I -O xhtml -S "$syntax" 2>/dev/null else - exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null + exec highlight --force --inline-css -f -I -O xhtml --syntax-by-name "$1" 2>/dev/null fi -- cgit v1.2.3-70-g09d2