diff options
Diffstat (limited to 'external')
-rwxr-xr-x | external/autopygmentize | 39 | ||||
-rw-r--r-- | external/markdown-processor.py | 2 | ||||
-rw-r--r-- | external/moin-parser.py | 2 | ||||
-rw-r--r-- | external/rst-directive.py | 2 |
4 files changed, 31 insertions, 14 deletions
diff --git a/external/autopygmentize b/external/autopygmentize index f18cac09..d2d05970 100755 --- a/external/autopygmentize +++ b/external/autopygmentize @@ -1,6 +1,6 @@ #!/bin/bash # Best effort auto-pygmentization with transparent decompression -# by Reuben Thomas 2008-2015 +# by Reuben Thomas 2008-2016 # 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 @@ -25,6 +25,7 @@ if [[ "$lexer" == text ]]; then text/x-awk) lexer=awk;; text/x-c) lexer=c;; text/x-c++) lexer=cpp;; + text/x-crystal) lexer=crystal;; text/x-diff) lexer=diff;; text/x-fortran) lexer=fortran;; text/x-gawk) lexer=gawk;; @@ -40,7 +41,6 @@ if [[ "$lexer" == text ]]; then text/x-po) lexer=po;; text/x-python) lexer=python;; text/x-ruby) lexer=ruby;; - text/x-crystal) lexer=crystal;; 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 @@ -66,19 +66,36 @@ if [[ "$lexer" == text ]]; then esac fi +# Find a preprocessor for compressed files +concat=cat +case $(file $file_common_opts --mime-type "$file") in + application/x-gzip) concat=zcat;; + application/x-bzip2) concat=bzcat;; + application/x-xz) concat=xzcat;; +esac + +# Find a suitable lexer, preceded by a hex dump for binary files +prereader="" encoding=$(file --mime-encoding --uncompress $file_common_opts "$file") if [[ $encoding == "binary" ]]; then - encoding="latin1" + prereader="od -x" # POSIX fallback + if [[ -n $(which hd) ]]; then + prereader="hd" # preferred + fi + lexer=hexdump + encoding=latin1 fi - if [[ -n "$lexer" ]]; then - concat=cat - case $(file $file_common_opts --mime-type "$file") in - application/x-gzip) concat=zcat;; - application/x-bzip2) concat=bzcat;; - application/x-xz) concat=xzcat;; - esac - exec $concat "$file" | pygmentize -O inencoding=$encoding $PYGMENTIZE_OPTS $options -l $lexer + reader="pygmentize -O inencoding=$encoding $PYGMENTIZE_OPTS $options -l $lexer" +fi + +# If we found a reader, run it +if [[ -n "$reader" ]]; then + if [[ -n "$prereader" ]]; then + exec $concat "$file" | $prereader | $reader + else + exec $concat "$file" | $reader + fi fi exit 1 diff --git a/external/markdown-processor.py b/external/markdown-processor.py index a3e178ec..cb8d793d 100644 --- a/external/markdown-processor.py +++ b/external/markdown-processor.py @@ -22,7 +22,7 @@ .. _Markdown: https://pypi.python.org/pypi/Markdown - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/external/moin-parser.py b/external/moin-parser.py index 9cb082a2..03a7c3c3 100644 --- a/external/moin-parser.py +++ b/external/moin-parser.py @@ -31,7 +31,7 @@ If you do not want to do that and are willing to accept larger HTML output, you can set the INLINESTYLES option below to True. - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ diff --git a/external/rst-directive.py b/external/rst-directive.py index f81677b6..de26dd03 100644 --- a/external/rst-directive.py +++ b/external/rst-directive.py @@ -31,7 +31,7 @@ .. _directive documentation: http://docutils.sourceforge.net/docs/howto/rst-directives.html - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ |