diff options
-rw-r--r-- | application/libraries/Pygments.php | 17 | ||||
-rwxr-xr-x | scripts/get_lexer_list.py | 14 |
2 files changed, 24 insertions, 7 deletions
diff --git a/application/libraries/Pygments.php b/application/libraries/Pygments.php index ddddf40d9..ab3868087 100644 --- a/application/libraries/Pygments.php +++ b/application/libraries/Pygments.php @@ -20,14 +20,23 @@ class Pygments { $this->filename = $filename; } + private static function get_pygments_info() { + return cache_function('pygments_info', 1800, function() { + ob_start(); + passthru("python ".escapeshellarg(FCPATH."scripts/get_lexer_list.py")); + $output = ob_get_clean(); + + return json_decode($output, true); + }); + } + public static function get_lexers() { return cache_function('lexers', 1800, function() { - $lexers = array(); $last_desc = ""; - exec("python ".escapeshellarg(FCPATH."scripts/get_lexer_list.py"), $output); - foreach ($output as $line) { - list($name, $desc) = explode("|", $line); + foreach (self::get_pygments_info() as $lexer) { + $desc = $lexer['fullname']; + $name = $lexer['names'][0]; if ($desc == $last_desc) { continue; } diff --git a/scripts/get_lexer_list.py b/scripts/get_lexer_list.py index 31e8e3650..0ef6fe97a 100755 --- a/scripts/get_lexer_list.py +++ b/scripts/get_lexer_list.py @@ -1,7 +1,15 @@ #!/usr/bin/python import pygments.lexers +import json -for fullname, names, exts, _ in pygments.lexers.get_all_lexers(): - for name in names: - print(("%s|%s") % (name, fullname)) +ret = [] + +for fullname, names, exts, mimetypes in pygments.lexers.get_all_lexers(): + ret.append({ + 'fullname': fullname, + 'names': names, + 'extentions': exts, + 'mimetypes': mimetypes, + }) +print(json.dumps(ret)) |