From 6d46760dfcbe6df31008c1a1c59a80319372adcd Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Mon, 20 May 2013 23:02:41 -0700 Subject: [PATCH 1/6] Fix for highlight-3.13 compatibility - No more override - No x86 build --- Common.m | 2 +- Info.plist | 23 +++++++++ QLColorCode.xcodeproj/project.pbxproj | 6 +-- colorize.sh | 4 +- override/config/filetypes.conf | 67 --------------------------- override/langDefs/c.lang | 62 ------------------------- override/langDefs/ml.lang | 54 --------------------- override/langDefs/objc.lang | 63 ------------------------- override/themes/ide-xcode.style | 26 ----------- override/themes/slateGreen.style | 32 ------------- override/themes/solarized-dark.style | 20 -------- override/themes/solarized-light.style | 20 -------- 12 files changed, 27 insertions(+), 352 deletions(-) delete mode 100644 override/config/filetypes.conf delete mode 100644 override/langDefs/c.lang delete mode 100644 override/langDefs/ml.lang delete mode 100644 override/langDefs/objc.lang delete mode 100644 override/themes/ide-xcode.style delete mode 100644 override/themes/slateGreen.style delete mode 100644 override/themes/solarized-dark.style delete mode 100644 override/themes/solarized-light.style diff --git a/Common.m b/Common.m index 70e5d8e..719a1a7 100644 --- a/Common.m +++ b/Common.m @@ -75,7 +75,7 @@ #endif @"9", @"fontSizePoints", @"Monaco", @"font", - @"ide-xcode", @"hlTheme", + @"edit-xcode", @"hlTheme", @"", @"extraHLFlags", @"", @"maxFileSize", @"UTF-8", @"textEncoding", diff --git a/Info.plist b/Info.plist index 04e483c..d6ef21e 100644 --- a/Info.plist +++ b/Info.plist @@ -16,6 +16,11 @@ com.apple.property-list org.tug.tex public.plain-text + public.shell-script + public.perl-script + public.python-script + com.netscape.javascript-source + com.apple.terminal.shell-script @@ -623,6 +628,24 @@ + + UTTypeConformsTo + + public.source-code + + UTTypeDescription + Source Code Types for QuickLook + UTTypeIdentifier + public.source-code + UTTypeTagSpecification + + public.filename-extension + + coffee + less + + + diff --git a/QLColorCode.xcodeproj/project.pbxproj b/QLColorCode.xcodeproj/project.pbxproj index 71fd8f9..2909063 100644 --- a/QLColorCode.xcodeproj/project.pbxproj +++ b/QLColorCode.xcodeproj/project.pbxproj @@ -26,11 +26,9 @@ 0E8776580D08E004005040B4 /* Common.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E8776560D08E004005040B4 /* Common.m */; }; 0E8776B70D08ED64005040B4 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8776B60D08ED64005040B4 /* WebKit.framework */; }; 0E8776BD0D08EDA4005040B4 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E8776BC0D08EDA4005040B4 /* AppKit.framework */; }; - 0E8FBB64141DA09D00269094 /* override in Resources */ = {isa = PBXBuildFile; fileRef = 0E8FBB56141DA09D00269094 /* override */; }; 0EB495D50D0FB13C00E86E0B /* colorize.sh in Resources */ = {isa = PBXBuildFile; fileRef = 0ECBBB5D0CFD447E00416538 /* colorize.sh */; }; 0EC047970CFBDADF009C986E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0EC047960CFBDADF009C986E /* Foundation.framework */; }; 0ECBBA6C0CFCA37500416538 /* QLColorCode.qlgenerator in Copy to Library */ = {isa = PBXBuildFile; fileRef = 8D576316048677EA00EA77CD /* QLColorCode.qlgenerator */; }; - 0EE90E861098CE5800468467 /* Script notes.txt in Resources */ = {isa = PBXBuildFile; fileRef = 0EE90E851098CE5800468467 /* Script notes.txt */; }; 2C05A19C06CAA52B00D84F6F /* GeneratePreviewForURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C05A19B06CAA52B00D84F6F /* GeneratePreviewForURL.m */; }; 61E3BCFB0870B4F2002186A0 /* GenerateThumbnailForURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 61E3BCFA0870B4F2002186A0 /* GenerateThumbnailForURL.m */; }; 8D576312048677EA00EA77CD /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 08FB77B6FE84183AC02AAC07 /* main.c */; settings = {ATTRIBUTES = (); }; }; @@ -249,8 +247,6 @@ files = ( 0EB495D50D0FB13C00E86E0B /* colorize.sh in Resources */, 8D5B49A804867FD3000E48DA /* InfoPlist.strings in Resources */, - 0EE90E861098CE5800468467 /* Script notes.txt in Resources */, - 0E8FBB64141DA09D00269094 /* override in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -297,7 +293,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = "/bin/zsh -x"; - shellScript = "set err_exit\ncd $PROJECT_DIR/highlight\nX=\"-arch i386 -arch x86_64 -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET\"\nexport CFLAGS=$X\nexport LDFLAGS=$X\nmake -j 2\n# Make sure it was built universal\nlipo -info src/highlight | grep -q i386 || exit 1\nlipo -info src/highlight | grep -q x86_64 || exit 1\nmake \\\n\tDESTDIR=$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH \\\n\tPREFIX=/highlight/ \\\n\tinstall\n\n"; + shellScript = "set err_exit\ncd $PROJECT_DIR/highlight\nX=\"-arch i386 -arch x86_64 -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET\"\nexport CFLAGS=$X\nexport CXXFLAGS=$X\nexport LDFLAGS=$X\nmake -j 2\n# Make sure it was built universal\n#lipo -info src/highlight | grep -q i386 || exit 1\nlipo -info src/highlight | grep -q x86_64 || exit 1\nmake \\\n\tDESTDIR=$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH \\\n\tPREFIX=/highlight/ \\\n\tinstall\n\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/colorize.sh b/colorize.sh index c4e878d..c8e84fb 100755 --- a/colorize.sh +++ b/colorize.sh @@ -34,9 +34,9 @@ debug Starting colorize.sh hlDir=$rsrcDir/highlight cmd=$hlDir/bin/highlight -cmdOpts=(-I --font $font --quiet --add-data-dir $rsrcDir/override \ +cmdOpts=(-I --font $font --quiet \ --data-dir $rsrcDir/highlight/share/highlight \ - --add-config-dir $rsrcDir/override/config --style $hlTheme \ + --add-config-dir $rsrcDir/etc/highlight --style $hlTheme \ --font-size $fontSizePoints --encoding $textEncoding ${=extraHLFlags} --validate-input) #for o in $cmdOpts; do echo $o\
; done diff --git a/override/config/filetypes.conf b/override/config/filetypes.conf deleted file mode 100644 index 817c730..0000000 --- a/override/config/filetypes.conf +++ /dev/null @@ -1,67 +0,0 @@ -# List of extensions -# ------------------------------------------ -# This file is a part of highlight, a free source code converter released under the GPL. -# -# Format: $ext(lang) = -# where lang is the file name of the language definition -# If there exists only one extension, you do not have to list it here. -# See README in the highlight directory for details. -# -# ---------- -# andre.simon1@gmx.de -# http:/www.andre-simon.de/ - -# Modified by Nathan Gray - -$ext(ada)=adb ads a gnad -$ext(ampl)=dat run -$ext(amtrix)=s4 s4t s4h hnd t4 -$ext(asm)=a51 29k 68s 68x x68 -$ext(asp)=asa -$ext(ats)=dats -$ext(aspect)=was wud -$ext(bat)=cmd -$ext(c)=c++ cpp cxx cc h hh hxx hpp pch cp pch++ -$ext(cfc)=cfm -$ext(cob)=cbl -$ext(diff)=patch -$ext(e)=se -$ext(erl)=hrl -$ext(euphoria)=ex exw exu ew eu -$ext(f77)=f for ftn -$ext(f90)=f95 -$ext(haskell)=hs icl -$ext(java)=groovy grv -$ext(lisp)=asd cl clisp el lsp sbcl -$ext(make)=mak mk -$ext(mib)=smi -$ext(ml)=mli ocaml mll mly -$ext(mod3)=mod m3 i3 ig mg -$ext(oberon)=ooc -$ext(objc)=mm -$ext(php)=php3 php4 php5 php6 -$ext(pike)=pmod -$ext(pl1)=ff fp fpp rpp sf sp spb spp sps wp wf wpp wps wpb bdy spe -$ext(pl)=perl cgi pm plx plex -$ext(progress)=p i w -$ext(rb)=ruby pp rjs -$ext(rexx)=rex rx the -$ext(sh)=bash ebuild eclass command -$ext(smalltalk)=st gst sq -$ext(sybase)=sp -$ext(tcl)=wish itcl -$ext(tex)=sty cls -$ext(vb)=bas basic bi vbs -$ext(verilog)=v -$ext(html)=htm xhtml -$ext(xml)=sgm sgml nrm ent hdr hub dtd wml vxml wml tld svg xsl ecf jnlp -$ext(fs)=fsx - -# Input file recognition -# Highlight matches the first input line with the listed expressions. -# Format: $shebang(lang) = - -$shebang(sh)=^#!(\/usr)?(\/local)?\/bin\/(bash|t?csh|[akz]?sh) -$shebang(pl)=^#!(\/usr)?(\/local)?\/bin\/perl -$shebang(py)=^#!(\/usr)?(\/local)?\/bin\/python -$shebang(awk)=^#!(\/usr)?(\/local)?\/bin\/[gn]?awk diff --git a/override/langDefs/c.lang b/override/langDefs/c.lang deleted file mode 100644 index 831b9ee..0000000 --- a/override/langDefs/c.lang +++ /dev/null @@ -1,62 +0,0 @@ -# C and C++ language definition file -# -# Author: Andre Simon -# Mail: andre.simon1@gmx.de -# Date: 24.7.2002 -# updated 12.1.04 to add more types (ansi c, iso 99) -# ------------------------------------------ -# This file is a part of highlight, a free source code converter released under the GPL. -# -# The file is used to describe keywords and special symbols of programming languages. -# See README in the highlight directory for details. -# -# New definition files for future releases of highlight are always appreciated ;) -# -# ---------- -# andre.simon1@gmx.de -# http:/www.andre-simon.de/ - -# Modified by Nathan Gray - -$DESCRIPTION=C and C++ - -$KEYWORDS(kwa)=goto break return continue asm case default if else switch while for do sizeof -typeof stdcall cdecl const_cast delete dynamic_cast goto namespace new pascal -reinterpret_cast static_cast this throw try catch using true false bitand and bitor or xor -compl and_eq or_eq xor_eq not not_eq - -$KEYWORDS(kwb)=int long short char void signed unsigned float double size_t wchar_t -ptrdiff_t sig_atomic_t fpos_t clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t static -const bool struct union enum size_t wchar_t ptrdiff_t sig_atomic_t fpos_t clock_t time_t -va_list jmp_buf FILE DIR div_t ldiv_t mbstate_t wctrans_t wint_t wctype_t bool complex -int8_t int16_t int32_t int64_t uint8_t uint16_t uint32_t uint64_t int_least8_t int_least16_t -int_least32_t int_least64_t uint_least8_t uint_least16_t uint_least32_t uint_least64_t -int_fast8_t int_fast16_t int_fast32_t int_fast64_t uint_fast8_t uint_fast16_t uint_fast32_t -uint_fast64_t intptr_t uintptr_t intmax_t uintmax_t - -$KEYWORDS(kwc)=typedef inline auto class explicit extern friend inline mutable operator -register template private protected public typeid virtual volatile - -$KEYWORDS(kwd)=regex((\w+?)\s*\() - -$KEYWORDS(fndef)=regex(^(?!typedef)[_a-zA-Z][*\w\t ]*(?:\n|[ \t])?[ \t]*[_a-zA-Z]\w*[ \t]*(?=\((?!\s*\*))) - -$STRINGDELIMITERS=" ' - -$SL_COMMENT=// - -$ML_COMMENT=/* */ - -$ALLOWNESTEDCOMMENTS=false - -$IGNORECASE=false - -$DIRECTIVE=# - -$ESCCHAR=\ - -$SYMBOLS= ( ) [ ] { } , ; . : & | < > ! = / * % + - ~ - -$CONTINUATIONSYMBOL=\ - -$REFORMATTING=true diff --git a/override/langDefs/ml.lang b/override/langDefs/ml.lang deleted file mode 100644 index 9ae86cc..0000000 --- a/override/langDefs/ml.lang +++ /dev/null @@ -1,54 +0,0 @@ -# Objective Caml language definition file -# -# Author: Andre Simon -# Mail: andre.simon1@gmx.de -# Date: 17.11.2003 -# ------------------------------------------ -# This file is a part of highlight, a free source code converter released under the GPL. -# -# The file is used to describe keywords and special symbols of programming languages. -# See README in the highlight directory for details. -# -# New definition files for future releases of highlight are always appreciated ;) -# -# ---------- -# andre.simon1@gmx.de -# http:/www.andre-simon.de/ - -# Modified by Nathan Gray - -# Character literals -$KEYWORDS(str)=regex('(?:[^\\]|\\.|\\[a-fA-F0-9]{2,3})') - -$KEYWORDS(kwa)=and as assert asr begin class constraint do done downto else -end exception external false for functor if in include inherit -initializer land lazy let lor lsl lsr lxor match method mod module mutable new -object of open or private rec sig struct then to true try type val virtual when -while with - -# Types and type variables -$KEYWORDS(kwb)=int float string char bool list exn array option format fpclass in_channel out_channel open_flag ref unit -$KEYWORDS(kwb)=regex((?<=type )(?:'[a-z]\w*[ \t]+)*[a-z]\w*|'[a-zA-Z_]+|\b[A-Z][a-zA-Z0-9_']*) -#$KEYWORDS(kwb)=regex((?<=type) +(?:'[a-z]\w*[ \t]+)*[a-z][\w']*) - -# Modules -$KEYWORDS(callr)=regex(\b[A-Z][a-zA-Z0-9_']*(?=\.)) - -# Function defs -$KEYWORDS(fndef)=fun function -$KEYWORDS(fndef)=regex(let([ \t]+rec)?[ \t]+([a-z][\w']*)[ \t]+[^=:,]) - -$STRINGDELIMITERS=" - -$ML_COMMENT=(* *) - -$ALLOWNESTEDCOMMENTS=true - -$IGNORECASE=false - -$ESCCHAR=\ - -$SYMBOLS= ( ) [ ] { } , ; : & | < > ! = / * % + - - -# This breaks keywords (kwa) for some reason: -# $IDENTIFIER=regex(\b[a-z_][a-zA-Z0-9_']*?) diff --git a/override/langDefs/objc.lang b/override/langDefs/objc.lang deleted file mode 100644 index 0bfa386..0000000 --- a/override/langDefs/objc.lang +++ /dev/null @@ -1,63 +0,0 @@ -# Objective C language definition file -# -# Author: Andr�Simon -# Mail: andre.simon1@gmx.de -# Date: 08.02.04 -# ------------------------------------------ -# This file is a part of highlight, a free source code converter released under the GPL. -# -# The file is used to describe keywords and special symbols of programming languages. -# See README in the highlight directory for details. -# -# New definition files for future releases of highlight are always appreciated ;) -# -# ---------- -# andre.simon1@gmx.de -# http:/www.andre-simon.de/ - -# Modified by Nathan Gray - -#### REMEMBER: \s includes \n! - -$KEYWORDS(kwa)=goto break return continue asm case default if else switch while for do sizeof typeof -typedef inline stdcall auto cdecl class const_cast delete dynamic_cast explicit -extern friend goto inline mutable namespace new operator pascal register reinterpret_cast private -protected public static_cast template this throw try catch typeid using virtual volatile true false -id Class SEL IMP BOOL oneway in out inout bycopy byref self super nil NIL TRUE FALSE - -$KEYWORDS(kwb)=int long short char void signed unsigned float double size_t wchar_t ptrdiff_t -sig_atomic_t fpos_t clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t static register auto -volatile extern const bool struct union enum - -#$KW_PREFIX(kwa)=@ - -$KEYWORDS(kwa)=regex(@\w+) - -$KEYWORDS(fndef)=regex(^(?!typedef)[_a-zA-Z][*\w\t ]*(?:\n|[ \t])?[ \t]*[_a-zA-Z]\w*[ \t]*(?=\((?!\s*\*))|^[ \t]*[\-+][ \t]*(?:\([ \t]*[_a-zA-Z]\w*[* \t]*\))?[ \t]*[_a-zA-Z]\w*(?=[ \t]*(?:\n[ \t]*)?(?=[:{]))) - -# Tmp. for debugging: -#$KEYWORDS(fndef)=regex(([_a-zA-Z]\w*)\s*(?:[:{])) - -$KEYWORDS(kwd)=regex((\w+?)\s*\() - -# A method call target is any identifier inside an open bracket followed by -# another identifier -$KEYWORDS(callr)=regex((?<=\[)\s*\w+(?=\s+[_a-zA-Z])) - -$KEYWORDS(str)=regex(@(?=")) - -$STRINGDELIMITERS=" ' - -$SL_COMMENT=// - -$ML_COMMENT=/* */ - -$ALLOWNESTEDCOMMENTS=false - -$IGNORECASE=false - -$DIRECTIVE=# - -$ESCCHAR=\ - -$SYMBOLS= ( ) [ ] { } , ; : & | < > ! = / * % + - diff --git a/override/themes/ide-xcode.style b/override/themes/ide-xcode.style deleted file mode 100644 index 00fe066..0000000 --- a/override/themes/ide-xcode.style +++ /dev/null @@ -1,26 +0,0 @@ -# xcode.style -# This File is part of highlight, a universal source code converter. -# See README in the highlight directory for documentation. - -# Modified by Nathan Gray - -$DEFAULTCOLOUR=#000000 -$BGCOLOUR=#ffffff -$FONTSIZE=#11 -$KW-GROUP(kwa)=#8f0055 -$KW-GROUP(kwb)=#8f0055 -$KW-GROUP(kwc)=#8f0055 -$KW-GROUP(kwd)=#005555 -$KW-GROUP(callr)=#000988 -$KW-GROUP(fndef)=#8f5500 -$NUMBER=#2300ff -$STRING=#c00000 -$KW-GROUP(str)=#c00000 -$ESCAPECHAR=#733710 -$COMMENT=#007f1c -$DIRECTIVE=#733710 -# for the string in: #include "foo" -$STRING-DIRECTIVE=#850055 -$LINE=#808080 -$SYMBOL=#000000 -$MARK-LINE=#ffffbb diff --git a/override/themes/slateGreen.style b/override/themes/slateGreen.style deleted file mode 100644 index 8aa3863..0000000 --- a/override/themes/slateGreen.style +++ /dev/null @@ -1,32 +0,0 @@ -# slateGreen.style -# See README in the highlight directory for documentation. - -$DEFAULTCOLOUR=#ffffff -$BGCOLOUR=#50573F -$FONTSIZE=11 -# Keywords -$KW-GROUP(kwa)=#EEA9B8 bold -# Types -$KW-GROUP(kwb)=#7FFFD4 -# Kinda unused?? In C it's used for type modifiers and typedef -$KW-GROUP(kwc)=#5FFCD4 bold - -# Objc: C fn call -$KW-GROUP(kwd)=#B0E0E6 -# Objc: method target, OCaml: module -$KW-GROUP(callr)=#FFC04B -$KW-GROUP(fndef)=#FFFF00 bold - - -$NUMBER=#00FF00 -$STRING=#ADFF2F -$KW-GROUP(str)=#ADFF2F -$ESCAPECHAR=#00FF00 -$COMMENT=#00EEEE italic -$DIRECTIVE=#EEDD82 -# for the string in: #include "foo" -$STRING-DIRECTIVE=#ADFF2F -$LINE=#EEDD82 -$MARK-LINE=#FFFF00 -# This is actually for punctuation -$SYMBOL=#EEEE00 diff --git a/override/themes/solarized-dark.style b/override/themes/solarized-dark.style deleted file mode 100644 index b172785..0000000 --- a/override/themes/solarized-dark.style +++ /dev/null @@ -1,20 +0,0 @@ -# solarized-dark.style -# This File is part of highlight, a universal source code converter. -# See README in the highlight directory for documentation. - -$DEFAULTCOLOUR=#839496 -$BGCOLOUR=#002b36 -$FONTSIZE=10 -$KW-GROUP(kwa)=#cb4b16 -$KW-GROUP(kwb)=#859900 -$KW-GROUP(kwc)=#cb4b16 -$KW-GROUP(kwd)=#93a1a1 -$NUMBER=#dc322f -$ESCAPECHAR=#6c71c4 -$STRING=#dc322f -$STRING-DIRECTIVE=#dc322f -$COMMENT=#586e75 -$DIRECTIVE=#6c71c4 -$LINE=#268bd2 -$SYMBOL=#93a1a1 -$MARK-LINE=#073642 diff --git a/override/themes/solarized-light.style b/override/themes/solarized-light.style deleted file mode 100644 index 9f42c81..0000000 --- a/override/themes/solarized-light.style +++ /dev/null @@ -1,20 +0,0 @@ -# solarized-light.style -# This File is part of highlight, a universal source code converter. -# See README in the highlight directory for documentation. - -$DEFAULTCOLOUR=#657b83 -$BGCOLOUR=#fdf6e3 -$FONTSIZE=10 -$KW-GROUP(kwa)=#cb4b16 -$KW-GROUP(kwb)=#859900 -$KW-GROUP(kwc)=#cb4b16 -$KW-GROUP(kwd)=#586e75 -$NUMBER=#dc322f -$ESCAPECHAR=#6c71c4 -$STRING=#dc322f -$STRING-DIRECTIVE=#dc322f -$COMMENT=#93a1a1 -$DIRECTIVE=#6c71c4 -$LINE=#268bd2 -$SYMBOL=#586e75 -$MARK-LINE=#073642 From 603011de578c920c5df5bd2c05855eb830a15590 Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Tue, 21 May 2013 18:21:51 -0700 Subject: [PATCH 2/6] Filename in QuickLook title --- colorize.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/colorize.sh b/colorize.sh index c8e84fb..dc1d537 100755 --- a/colorize.sh +++ b/colorize.sh @@ -37,6 +37,7 @@ cmd=$hlDir/bin/highlight cmdOpts=(-I --font $font --quiet \ --data-dir $rsrcDir/highlight/share/highlight \ --add-config-dir $rsrcDir/etc/highlight --style $hlTheme \ + --doc-title "${target##*/}" \ --font-size $fontSizePoints --encoding $textEncoding ${=extraHLFlags} --validate-input) #for o in $cmdOpts; do echo $o\
; done From 4a2c0856cfe353e22d6ec46394f8332a2d2f7e68 Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Tue, 21 May 2013 18:25:02 -0700 Subject: [PATCH 3/6] Handle QuickLook for public.data files ... ... which usually lack file extensions, e.g., Makefile, README, etc. (inspired by QLStephen[1]). We might need to adapt the whitelist/blacklist approach used in QLStephen. [1]: https://github.com/whomwah/qlstephen --- Info.plist | 1 + colorize.sh | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Info.plist b/Info.plist index d6ef21e..a54696d 100644 --- a/Info.plist +++ b/Info.plist @@ -12,6 +12,7 @@ LSItemContentTypes public.source-code + public.data public.xml com.apple.property-list org.tug.tex diff --git a/colorize.sh b/colorize.sh index dc1d537..1c9e0b4 100755 --- a/colorize.sh +++ b/colorize.sh @@ -81,20 +81,23 @@ case $target in lang=pro fi ;; - * ) + *.* ) lang=${target##*.} - ;; + ;; + * ) + lang= + ;; esac debug Resolved $target to language $lang go4it () { debug Generating the preview if [ $thumb = "1" ]; then - $reader | head -n 100 | head -c 20000 | $cmd --syntax $lang $cmdOpts && exit 0 + $reader | head -n 100 | head -c 20000 | $cmd --syntax "$lang" $cmdOpts && exit 0 elif [ -n "$maxFileSize" ]; then - $reader | head -c $maxFileSize | $cmd --syntax $lang $cmdOpts && exit 0 + $reader | head -c $maxFileSize | $cmd --syntax "$lang" $cmdOpts && exit 0 else - $reader | $cmd --syntax $lang $cmdOpts && exit 0 + $reader | $cmd --syntax "$lang" $cmdOpts && exit 0 fi } From 2ae03bbb3d3686623798fd9504e9b730a3b86394 Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Sat, 15 Jun 2013 12:40:31 -0700 Subject: [PATCH 4/6] Cleaned up colorize.sh - zsh -> bash - intuitive handling of special cases - clearer flow of fallback to plain text --- colorize.sh | 128 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 47 deletions(-) diff --git a/colorize.sh b/colorize.sh index 1c9e0b4..eff7fc6 100755 --- a/colorize.sh +++ b/colorize.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/bash # This code is licensed under the GPL v2. See LICENSE.txt for details. @@ -6,7 +6,7 @@ # QLColorCode # # Created by Nathaniel Gray on 11/27/07. -# Copyright 2007 Nathaniel Gray. +# Copyright 2007 Nathaniel Gray, Jaeho Shin. # Expects $1 = path to resources dir of bundle # $2 = name of file to colorize @@ -17,96 +17,130 @@ ############################################################################### # Fail immediately on failure of sub-command -setopt err_exit +# Also fail whenever undefined variables are used +set -eu -rsrcDir=$1 -target=$2 -thumb=$3 +: \ + ${qlcc_debug:=} \ + ${qlcc_text_fallback:=false} \ + ${maxFileSize:=} \ + ${extraHLFlags:=} \ + # -debug () { - if [ "x$qlcc_debug" != "x" ]; then if [ "x$thumb" = "x0" ]; then - echo "QLColorCode: $@" 1>&2 - fi; fi -} +RsrcDir=$1 +Target=$2 +case $3 in + 1) Thumb=true ;; + 0|*) Thumb=false ;; +esac -debug Starting colorize.sh -#echo target is $target +debug() { [ -z "$qlcc_debug" ] || ! $Thumb || echo >&2 "QLColorCode: $@"; } -hlDir=$rsrcDir/highlight -cmd=$hlDir/bin/highlight -cmdOpts=(-I --font $font --quiet \ - --data-dir $rsrcDir/highlight/share/highlight \ - --add-config-dir $rsrcDir/etc/highlight --style $hlTheme \ - --doc-title "${target##*/}" \ - --font-size $fontSizePoints --encoding $textEncoding ${=extraHLFlags} --validate-input) +debug Starting colorize.sh -#for o in $cmdOpts; do echo $o\
; done +read-target() { cat "$Target"; } -debug Setting reader -reader=(cat $target) +# Define how we invoke highlight +# (See: http://www.andre-simon.de/doku/highlight/en/highlight.html) +lang= +highlightOpts=( +--quiet +--validate-input +--encoding "$textEncoding" +--doc-title "${Target##*/}" +--include-style +--style "$hlTheme" +--font "$font" +--font-size "$fontSizePoints" +--data-dir "$RsrcDir"/highlight/share/highlight +--add-config-dir "$RsrcDir"/etc/highlight +) +invoke-highlight() { + set -- "${highlightOpts[@]}" $extraHLFlags "$@" + if [ -n "$lang" ]; then + set -- --syntax "$lang" "$@" + fi + "$RsrcDir"/highlight/bin/highlight "$@" +} -debug Handling special cases -case $target in +case ${Target##*/} in *.graffle ) # some omnigraffle files are XML and get passed to us. Ignore them. exit 1 ;; + *.plist ) lang=xml - reader=(/usr/bin/plutil -convert xml1 -o - $target) + read-target() { /usr/bin/plutil -convert xml1 -o - "$Target"; } ;; + *.h ) - if grep -q "@interface" $target &> /dev/null; then + if grep -q "@interface" "$Target" &>/dev/null; then lang=objc else lang=h fi ;; + *.m ) # look for a matlab-style comment in the first 10 lines, otherwise # assume objective-c. If you never use matlab or never use objc, # you might want to hardwire this one way or the other - if head -n 10 $target | grep -q "^[ ]*%" &> /dev/null; then + if head -n 10 "$Target" | grep -q "^[ ]*%" &>/dev/null; then lang=m else lang=objc fi ;; + *.pro ) # Can be either IDL or Prolog. Prolog uses /* */ and % for comments. # IDL uses ; - if head -n 10 $target | grep -q "^[ ]*;" &> /dev/null; then + if head -n 10 "$Target" | grep -q "^[ ]*;" &>/dev/null; then lang=idlang else lang=pro fi ;; + *.* ) - lang=${target##*.} + lang=${Target##*.} + ;; + + Makefile ) + lang=make ;; - * ) - lang= + + LICENSE |\ + COPYING |\ + README ) + lang=txt ;; esac -debug Resolved $target to language $lang +debug Resolved $Target to language $lang -go4it () { +generate-preview () { debug Generating the preview - if [ $thumb = "1" ]; then - $reader | head -n 100 | head -c 20000 | $cmd --syntax "$lang" $cmdOpts && exit 0 + if $Thumb; then + head -n 100 | head -c 20000 | + invoke-highlight elif [ -n "$maxFileSize" ]; then - $reader | head -c $maxFileSize | $cmd --syntax "$lang" $cmdOpts && exit 0 + head -c "$maxFileSize" | + invoke-highlight else - $reader | $cmd --syntax "$lang" $cmdOpts && exit 0 + invoke-highlight fi } -setopt no_err_exit -debug First try... -go4it -# Uh-oh, it didn't work. Fall back to rendering the file as plain -debug First try failed, second try... -lang=txt -go4it -debug Reached the end of the file. That should not happen. -exit 101 +if ! read-target | generate-preview; then + # Uh-oh, it didn't work, + if $qlcc_text_fallback; then + # Fallback to rendering as plain text + debug First try failed, fallback to plain text + lang=txt + read-target | generate-preview + else + # Let other QuickLook generator handle + exit 2 + fi +fi From e38b0534540094252480154744e0903208e0f501 Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Sun, 14 Jul 2013 23:07:44 -0700 Subject: [PATCH 5/6] Using file --mime-type to detect text for fallback --- colorize.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/colorize.sh b/colorize.sh index eff7fc6..f8a52c7 100755 --- a/colorize.sh +++ b/colorize.sh @@ -133,8 +133,8 @@ generate-preview () { } if ! read-target | generate-preview; then - # Uh-oh, it didn't work, - if $qlcc_text_fallback; then + # Uh-oh, it didn't work, see if we can fallback to text + if $qlcc_text_fallback || [[ $(file --brief --mime-type "$Target") = text/* ]]; then # Fallback to rendering as plain text debug First try failed, fallback to plain text lang=txt From daeaeb1ec8a4732a4ec0231907a89a5f8479ae10 Mon Sep 17 00:00:00 2001 From: Jaeho Shin Date: Sun, 29 Nov 2015 12:20:08 -0800 Subject: [PATCH 6/6] Adds .dylib bundling steps for highlight e.g., lua.5.1.dylib --- QLColorCode.xcodeproj/project.pbxproj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/QLColorCode.xcodeproj/project.pbxproj b/QLColorCode.xcodeproj/project.pbxproj index 2909063..b699311 100644 --- a/QLColorCode.xcodeproj/project.pbxproj +++ b/QLColorCode.xcodeproj/project.pbxproj @@ -220,6 +220,8 @@ /* Begin PBXProject section */ 089C1669FE841209C02AAC07 /* Project object */ = { isa = PBXProject; + attributes = { + }; buildConfigurationList = 2CA326220896AD4900168862 /* Build configuration list for PBXProject "QLColorCode" */; compatibilityVersion = "Xcode 3.0"; developmentRegion = English; @@ -293,7 +295,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = "/bin/zsh -x"; - shellScript = "set err_exit\ncd $PROJECT_DIR/highlight\nX=\"-arch i386 -arch x86_64 -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET\"\nexport CFLAGS=$X\nexport CXXFLAGS=$X\nexport LDFLAGS=$X\nmake -j 2\n# Make sure it was built universal\n#lipo -info src/highlight | grep -q i386 || exit 1\nlipo -info src/highlight | grep -q x86_64 || exit 1\nmake \\\n\tDESTDIR=$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH \\\n\tPREFIX=/highlight/ \\\n\tinstall\n\n"; + shellScript = "set err_exit\ncd $PROJECT_DIR/highlight\nX=\"-arch i386 -arch x86_64 -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET\"\nexport CFLAGS=$X\nexport CXXFLAGS=$X\nexport LDFLAGS=$X\nmake -j CFLAGS=$X CXXFLAGS=$X LDFLAGS=$X\n# Make sure it was built universal\nlipo -info src/highlight | grep -q i386 || exit 1\nlipo -info src/highlight | grep -q x86_64 || exit 1\nmake \\\n\tDESTDIR=$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH \\\n\tPREFIX=/highlight/ \\\n\tinstall\n\n# Make sure all required .dylib are bundled\nDYLIBS=`otool -L src/highlight | grep \"^\\t\" | grep -v \"/usr/lib/\" | awk -F' ' '{ print $1 }'`\nhighlight_root=$BUILT_PRODUCTS_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/highlight\nmkdir -p $highlight_root/lib\nfor dylib in $DYLIBS; do\n cp -f $dylib $highlight_root/lib/\n install_name_tool -change $dylib @executable_path/../lib/`basename $dylib` $highlight_root/bin/highlight\ndone"; }; /* End PBXShellScriptBuildPhase section */ @@ -388,7 +390,7 @@ GCC_PREPROCESSOR_DEFINITIONS = DEBUG; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.6; + MACOSX_DEPLOYMENT_TARGET = 10.11; PREBINDING = NO; SDKROOT = macosx; }; @@ -397,12 +399,11 @@ 2CA326240896AD4900168862 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; - ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc"; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CURRENT_PROJECT_VERSION = 2.0.2; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.6; + MACOSX_DEPLOYMENT_TARGET = 10.11; PREBINDING = NO; SDKROOT = macosx; };