summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorrrt <rrt@sc3d.org>2013-01-10 15:22:10 +0000
committerrrt <rrt@sc3d.org>2013-01-10 15:22:10 +0000
commit89036fff602cf7ad8de8bfe2c15531b46111662b (patch)
tree52b1b0351cf777197564c61070d439c40db4b997 /external
parentfc6a95bd275024fe9f71963b940fa1fa8358e65f (diff)
downloadpygments-89036fff602cf7ad8de8bfe2c15531b46111662b.tar.gz
autopygmentize: various improvements
Fix encoding detection using file (add --brief flag) Remove workaround for non-issue #799 Only call pygmentize once, and thereby always get the benefit of encoding detection.
Diffstat (limited to 'external')
-rwxr-xr-x[-rw-r--r--]external/autopygmentize96
1 files changed, 46 insertions, 50 deletions
diff --git a/external/autopygmentize b/external/autopygmentize
index ad9faaeb..ee32a301 100644..100755
--- a/external/autopygmentize
+++ b/external/autopygmentize
@@ -1,6 +1,6 @@
#!/bin/sh
# Best effort auto-pygmentization with transparent decompression
-# (c) Reuben Thomas 2012
+# (c) Reuben Thomas 2012-2013
# This program is in the public domain.
# Strategy: first see if pygmentize can find a lexer; if not, ask file; if that finds nothing, fail
@@ -8,60 +8,56 @@
# This program can be used as a .lessfilter for the less pager to auto-color less's output
-if [ `pygmentize -N $1` != "text" ]; then
- pygmentize $PYGMENTIZE_OPTS "$1"
- exit 0
-fi
+lexer=`pygmentize -N "$1"`
+if [ "$lexer" = "text" ]; then
+ file_common_opts="--brief --dereference --uncompress"
-file_common_opts="--brief --dereference --uncompress"
-
-unset lexer
-case `file --mime-type $file_common_opts "$1"` in
- application/xml|image/svg+xml) lexer=xml;;
- text/html) lexer=html;;
- text/troff) lexer=nroff;;
- text/x-asm) lexer=nasm;;
- text/x-awk) lexer=awk;;
- text/x-c) lexer=c;;
- text/x-c++) lexer=cpp;;
- text/x-diff) lexer=diff;;
- text/x-fortran) lexer=fortran;;
- text/x-gawk) lexer=gawk;;
- text/x-java) lexer=java;;
- text/x-lisp) lexer=common-lisp;;
- text/x-lua) lexer=lua;;
- text/x-makefile) lexer=make;;
- text/x-msdos-batch) lexer=bat;;
- text/x-nawk) lexer=nawk;;
- text/x-pascal) lexer=pascal;;
- text/x-perl) lexer=perl;;
- text/x-php) lexer=php;;
- text/x-po) lexer=po;;
- text/x-python) lexer=python;;
- text/x-ruby) lexer=ruby;;
- text/x-shellscript) lexer=sh;;
- text/x-tcl) lexer=tcl;;
- text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
-
- # Types that file outputs which pygmentize didn't support as of file 5.11, pygments 1.5
- # text/calendar
- # text/PGP
- # text/rtf
- # text/texmacs
- # text/x-bcpl
- # text/x-info
- # text/x-m4
- # text/x-vcard
- # text/x-xmcd
-esac
+ unset lexer
+ case `file --mime-type $file_common_opts "$1"` in
+ application/xml|image/svg+xml) lexer=xml;;
+ text/html) lexer=html;;
+ text/troff) lexer=nroff;;
+ text/x-asm) lexer=nasm;;
+ text/x-awk) lexer=awk;;
+ text/x-c) lexer=c;;
+ text/x-c++) lexer=cpp;;
+ text/x-diff) lexer=diff;;
+ text/x-fortran) lexer=fortran;;
+ text/x-gawk) lexer=gawk;;
+ text/x-java) lexer=java;;
+ text/x-lisp) lexer=common-lisp;;
+ text/x-lua) lexer=lua;;
+ text/x-makefile) lexer=make;;
+ text/x-msdos-batch) lexer=bat;;
+ text/x-nawk) lexer=nawk;;
+ text/x-pascal) lexer=pascal;;
+ text/x-perl) lexer=perl;;
+ text/x-php) lexer=php;;
+ text/x-po) lexer=po;;
+ text/x-python) lexer=python;;
+ text/x-ruby) lexer=ruby;;
+ text/x-shellscript) lexer=sh;;
+ text/x-tcl) lexer=tcl;;
+ text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
+
+ # Types that file outputs which pygmentize didn't support as of file 5.11, pygments 1.5
+ # text/calendar
+ # text/PGP
+ # text/rtf
+ # text/texmacs
+ # text/x-bcpl
+ # text/x-info
+ # text/x-m4
+ # text/x-vcard
+ # text/x-xmcd
+ esac
+fi
-encoding=`file --mime-encoding $file_common_opts "$1"`
+encoding=`file --brief --mime-encoding $file_common_opts "$1"`
if [ -n "$lexer" ]; then
# FIXME: Specify input encoding rather than output encoding https://bitbucket.org/birkenfeld/pygments-main/issue/800
- # FIXME: Encoding argument ignored on stdin https://bitbucket.org/birkenfeld/pygments-main/issue/799
- #zcat "$1" | pygmentize -O encoding=$encoding,outencoding=UTF-8 $PYGMENTIZE_OPTS -l $lexer
- pygmentize -O encoding=$encoding,outencoding=UTF-8 $PYGMENTIZE_OPTS -l $lexer $1
+ zcat "$1" | pygmentize -O encoding=$encoding,outencoding=UTF-8 $PYGMENTIZE_OPTS -l $lexer
exit 0
fi