ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/website/www.git/commit/?id=419fa515f24e97926733a1628ee3ffc876c2ab7d

commit 419fa515f24e97926733a1628ee3ffc876c2ab7d
Author: Andy Williams <a...@andywilliams.me>
Date:   Mon Oct 30 16:21:24 2017 +0000

    Revert "Revert "WIKI CUSTOM - geshi - add custom code hilighter extensions""
    
    This reverts commit a34d54426e40537d4fa5e3080f62286075d7c025.
---
 public_html/inc/geshi.php       | 21 +++++++++++++++++----
 public_html/inc/parserutils.php | 20 ++++++++++++++++++--
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/public_html/inc/geshi.php b/public_html/inc/geshi.php
index c6ff9ef7..e4b142b8 100644
--- a/public_html/inc/geshi.php
+++ b/public_html/inc/geshi.php
@@ -594,7 +594,8 @@ class GeSHi {
      *               {@link GeSHi->set_language_path()}
      * @since 1.0.0
      */
-    function GeSHi($source = '', $language = '', $path = '') {
+    function GeSHi($source = '', $language = '', $path = '', $extndir = '') {
+        $this->extndir = $extndir;
         if (!empty($source)) {
             $this->set_source($source);
         }
@@ -689,6 +690,10 @@ class GeSHi {
             // this language is already loaded!
             return;
         }
+        if (!empty($this->extndir)) {
+            $file_extn_link = $this->extndir . '/' . $language . 
'/keyword-link.txt';
+            $file_extn_list = $this->extndir . '/' . $language . 
'/keyword-list.txt';
+        }
 
         $this->language = $language;
 
@@ -702,7 +707,7 @@ class GeSHi {
         }
 
         // Load the language for parsing
-        $this->load_language($file_name);
+        $this->load_language($file_name, $file_extn_link, $file_extn_list);
     }
 
     /**
@@ -3740,7 +3745,7 @@ class GeSHi {
      * @access private
      * @todo Needs to load keys for lexic permissions for keywords, regexps etc
      */
-    function load_language($file_name) {
+    function load_language($file_name, $file_extn_link, $file_extn_list) {
         if ($file_name == $this->loaded_language) {
             // this file is already loaded!
             return;
@@ -3755,6 +3760,14 @@ class GeSHi {
         //Load the language file
         require $file_name;
 
+        if (!empty($file_extn_link) && !empty($file_extn_list) &&
+            file_exists($file_extn_link) && file_exists($file_extn_list)) {
+            $link_array = file($file_extn_link, FILE_IGNORE_NEW_LINES | 
FILE_SKIP_EMPTY_LINES);
+            $keys_array = file($file_extn_list, FILE_IGNORE_NEW_LINES | 
FILE_SKIP_EMPTY_LINES);
+            $language_data['URLS'][5] = $link_array[0];
+            $language_data['KEYWORDS'][5] = $keys_array;
+        }
+
         // Perhaps some checking might be added here later to check that
         // $language data is a valid thing but maybe not
         $this->language_data = $language_data;
@@ -4772,4 +4785,4 @@ if (!function_exists('geshi_highlight')) {
     }
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/public_html/inc/parserutils.php b/public_html/inc/parserutils.php
index 17c331ef..d17580ed 100644
--- a/public_html/inc/parserutils.php
+++ b/public_html/inc/parserutils.php
@@ -743,17 +743,33 @@ function p_xhtml_cached_geshi($code, $language, 
$wrapper='pre') {
     // remove any leading or trailing blank lines
     $code = preg_replace('/^\s*?\n|\s*?\n$/','',$code);
 
+    $extn_dir = $conf['datadir'] . '/' . $conf['code_extn'];
+    if (!file_exists($extn_dir)) {
+        $extn_dir = '';
+    }
+    else {
+        $extn_link = $extn_dir . '/' . $language . '/keyword-link.txt';
+        $extn_list = $extn_dir . '/' . $language . '/keyword-list.txt';
+        if (!file_exists($extn_link) || !file_exists($extn_list)) {
+            $extn_link = '';
+            $extn_list = '';
+        }
+    }
+
     $cache = getCacheName($language.$code,".code");
     $ctime = @filemtime($cache);
     if($ctime && !$INPUT->bool('purge') &&
+            ((!empty($extn_link) &&
+              (($ctime > filemtime($extn_link)) &&
+               ($ctime > filemtime($extn_list)))) ||
+             (empty($extn_link))) &&
             $ctime > filemtime(DOKU_INC.'inc/geshi.php') &&                 // 
geshi changed
             $ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') &&  // 
language syntax definition changed
             $ctime > filemtime(reset($config_cascade['main']['default']))){ // 
dokuwiki changed
         $highlighted_code = io_readFile($cache, false);
 
     } else {
-
-        $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi');
+        $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi', 
$conf['datadir'] . '/' . $conf['code_extn']);
         $geshi->set_encoding('utf-8');
         $geshi->enable_classes();
         $geshi->set_header_type(GESHI_HEADER_PRE);

-- 


Reply via email to