On 21-02-12 14:27, Lukas Fleischer wrote:
On Tue, Feb 21, 2012 at 01:13:31PM +0100, Ferry Huberts wrote:
From: Ferry Huberts<[email protected]>

Signed-off-by: Ferry Huberts<[email protected]>
---
  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&nbsp; is a workaround for empty lines getting filtered out
-exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null | sed -r 
's/^[[:space:]]*$/\&nbsp;/'
+# 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&nbsp; is a workaround for empty lines getting filtered out
+  exec highlight --force -f -I -X -S $EXTENSION 2>/dev/null | sed -r 
's/^[[:space:]]*$/\&nbsp;/'
+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&nbsp; is a workaround for empty lines getting filtered out
+  exec highlight -f -I -O xhtml -S $EXTENSION 2>/dev/null | sed -r 
's/^[[:space:]]*$/\&nbsp;/'
+fi

Good to know that this is broken, but your solution seems like a hack
without any explanation... Could you elaborate why this is needed and
why this is the proper way to fix this regression, please?


ok, thought it was clear.

On CentOS 6.2 (use highlight from EPEL), when highlight doesn't know about an EXTENSION, it outputs a lua error and _no_ text, even when the --force option is used.


see https://bugzilla.redhat.com/show_bug.cgi?id=795567

--
Ferry Huberts

_______________________________________________
cgit mailing list
[email protected]
http://hjemli.net/mailman/listinfo/cgit

Reply via email to