raster pushed a commit to branch master.

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

commit c55c1d32bb61536b57e171867d96719ce19f4b57
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Tue Apr 14 16:05:09 2015 +0900

    WIKI CUSTOM - geshi - add custom code hilighter extensions
    
    name "WIKI CUSTOM" above to find it easy to identify custom patches to
    dokuwiki beyond having raw as-per-upstream code. then "geshi" as to
    what was modded. this mods geshi and adds a config var. documentation
    here:
    
    /* new config - patches to dokuwiki enabled this. this is a directory
     * realtive to 'datadir' config above where we store metadata right in the
     * wiki itself to holid linking and documentation for keywords in specific
     * languages like c, lua, cpp, js, python etc. you need the below directory
     * and then like
     * $dir/$language/keyword-link.txt
     * #dir/$language/keyword-list.txt
     *
     * where $dir is the below base dir and $language is the lang in a code
     * block like c, cpp, js etc. so for example you may have:
     *
     * docs/generated/c/keyword-link.txt
     * docs/generated/c/keyword-list.txt
     *
     * inside your "pages" dir for the wiki. the link file is simply a base url
     * pattern that allows you to direct where a detected keyword link is 
pointed
     * to such as:
     *
     * /docs/generated/c/keywords/{FNAMEL}
     *
     * this replaces {FNAMEL} with the keyword. so if ou have in the wiki there
     * a keywords directory and keyword.txt - this cam be the documentation for
     * that keyword. this is done to alllow auto-linking of code examples as
     * well as anything else code-related to appropriate documentation for a
     * project without people having to hand link in everything all the time,
     * much like what doxygen does, but in dokuwiki. right now it only works
     * inside code blocks syntax hilighted by geshi
     */
    $conf['code_extn'] = 'docs/generated';
    
    you might ewant to set:
    
    /* max cache time for a wiki pagee - this is so that code keyword
     * hilighting works even if a page doesn't have a
     * ~~NOCACHE~~ directive in it. if it has this in it, then code keyword
     * extension hilighting is updated immediately
     */
    $conf['cachetime'] = 3600;
    
    (max page cache = 1h).
---
 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 c6ff9ef..e4b142b 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 17c331e..d17580e 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