summaryrefslogtreecommitdiff
path: root/usr/lib
diff options
context:
space:
mode:
authorXiao Pan <gky44px1999@gmail.com>2024-02-25 09:25:54 +0000
committerXiao Pan <gky44px1999@gmail.com>2024-02-25 09:25:54 +0000
commitc5c96be29effb246cca890bc342fbc207da34dfe (patch)
tree2d3bf4b436dd5a9df56c91a3c810b654f4bc65dc /usr/lib
parentd708af68c3369b5da525d10985a095217f91cedc (diff)
highlight use --syntax-by-name to simplify code
Diffstat (limited to 'usr/lib')
-rwxr-xr-xusr/lib/cgit/filters/syntax-highlighting-edited.sh21
1 files changed, 10 insertions, 11 deletions
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