[PATCH v2 3/3] highlight: fix syntax highlighting for program versions > 2

Ferry Huberts mailings at hupie.com
Tue Feb 21 13:13:31 CET 2012


From: Ferry Huberts <ferry.huberts at pelagic.nl>

Signed-off-by: Ferry Huberts <ferry.huberts at pelagic.nl>
---
 filters/syntax-highlighting.sh |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/filters/syntax-highlighting.sh b/filters/syntax-highlighting.sh
index 0f97fea..387960d 100755
--- a/filters/syntax-highlighting.sh
+++ b/filters/syntax-highlighting.sh
@@ -42,5 +42,23 @@ declare EXTENSION="${BASENAME##*.}"
 # map Makefile and Makefile.* to .mk
 [ "${BASENAME%%.*}" == "Makefile" ] && EXTENSION=mk
 
-# the sed with   is a workaround for empty lines getting filtered out
-exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null | sed -r 's/^[[:space:]]*$/\ /'
+# get highlight version
+declare regex='^[[:space:]]*highlight[[:space:]]+version[[:space:]]+([[:digit:]]+).*'
+declare -i highlightVersion=$(highlight --version | grep -E "${regex}" | sed -r "s/${regex}/\1/")
+
+if [[ ${highlightVersion} -le 2 ]]; then
+  # for highlight  <= 2.x
+
+  # the sed with   is a workaround for empty lines getting filtered out
+  exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null | sed -r 's/^[[:space:]]*$/\ /'
+else
+  # for other highlight versions
+
+  # workaround for --force bug:
+  # set to plain text when highlight doesn't know the format
+  echo "test" | highlight -f -I -O xhtml -S $EXTENSION &>/dev/null
+  [ ${?} -ne 0 ] && EXTENSION="txt"
+
+  # the sed with   is a workaround for empty lines getting filtered out
+  exec highlight -f -I -O xhtml -S $EXTENSION 2>/dev/null | sed -r 's/^[[:space:]]*$/\ /'
+fi
-- 
1.7.7.6





More information about the CGit mailing list