diff options
-rw-r--r-- | application/libraries/Pygments.php | 4 | ||||
-rw-r--r-- | application/tests/test_libraries_pygments.php | 4 | ||||
-rwxr-xr-x | scripts/get_lexer_list.py | 2 |
3 files changed, 7 insertions, 3 deletions
diff --git a/application/libraries/Pygments.php b/application/libraries/Pygments.php index 13d82d2ad..04d4e670c 100644 --- a/application/libraries/Pygments.php +++ b/application/libraries/Pygments.php @@ -21,7 +21,7 @@ class Pygments { } private static function get_pygments_info() { - return cache_function_full('pygments_info', 1800, function() { + return cache_function_full('pygments_info-v2', 1800, function() { ob_start(); passthru("python ".escapeshellarg(FCPATH."scripts/get_lexer_list.py")); $output = ob_get_clean(); @@ -148,7 +148,7 @@ class Pygments { // fall back to pygments own list if not found in our list foreach (self::get_pygments_info() as $lexer) { if (isset($lexer['mimetypes'][$this->mimetype])) { - return $lexer; + return $lexer['names'][0]; } } diff --git a/application/tests/test_libraries_pygments.php b/application/tests/test_libraries_pygments.php index ba2103e50..f88a4bcbd 100644 --- a/application/tests/test_libraries_pygments.php +++ b/application/tests/test_libraries_pygments.php @@ -32,6 +32,10 @@ class test_libraries_pygments extends Test { $p = new \libraries\Pygments('/invalid/filepath', 'application/x-php', 'stdin'); $this->t->is($p->autodetect_lexer(), 'php', "application/php should be php"); + // This is from pygments and not our hardcoded list + $p = new \libraries\Pygments('/invalid/filepath', 'text/x-pascal', 'stdin'); + $this->t->is($p->autodetect_lexer(), 'delphi', "text/x-pascal should be delphi"); + $p = new \libraries\Pygments('/invalid/filepath', 'application/octet-stream', 'stdin'); $this->t->is($p->autodetect_lexer(), false, "application/octet-stream should return false"); } diff --git a/scripts/get_lexer_list.py b/scripts/get_lexer_list.py index 9453ff733..50e93bde5 100755 --- a/scripts/get_lexer_list.py +++ b/scripts/get_lexer_list.py @@ -11,7 +11,7 @@ def dictify(list): for fullname, names, exts, mimetypes in pygments.lexers.get_all_lexers(): ret.append({ 'fullname': fullname, - 'names': dictify(names), + 'names': names, 'extentions': dictify(exts), 'mimetypes': dictify(mimetypes), }) |