Syntax-Highlighting

如何為 cgit 執行 syntax-highlighting.sh 命令來檢查它是否正常工作?

  • September 7, 2017

cgit 安裝中的語法突出顯示選項無法正常工作,如果所有必要的參數都存在,我想看看它是否可以從命令行正常執行。

中的選項/etc/cgitrc設置正確。

source-filter=/usr/lib/cgit/filters/syntax-highlighting.sh

例如,當我在highlightbash 文件上執行命令時,css 和 span 類在輸出中,但是當我在文件上執行 /usr/lib/cgit/filters/syntax-highlighting.sh 時,css 和 span 標籤不會顯示。

腳本中的命令實際highlight命令(最後一行)是

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

事實證明,為了讓語法高亮在 cgit 下工作,指定語法高亮的行必須出現在 repo 位置的行之前。在下面給出的範例中,如果該source-filter行位於該include行之後,則語法高亮將失敗。

source-filter=/usr/lib/cgit/filters/syntax-highlighting.py   
include=/home/infosys/sites/cgit.local/www/cgitrepos

我檢查了,除非它被記錄在某個地方,否則它一定是一個錯誤。也許某些設計問題需要這樣。

更多資訊在https://wiki.archlinux.org/index.php/Cgit

引用自:https://unix.stackexchange.com/questions/379328