[Xfce4-commits] <wiki:master> Add the xfcedocs plugin.

Nick Schermer noreply at xfce.org
Tue Jan 3 20:02:03 CET 2012


Updating branch refs/heads/master
         to 37428aa34fa85f7bd821b84b5d89ffb5515cdd40 (commit)
       from a82faa6e504ce80bcd99d499503b2311b178c7e5 (commit)

commit 37428aa34fa85f7bd821b84b5d89ffb5515cdd40
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Jan 3 19:59:45 2012 +0100

    Add the xfcedocs plugin.

 lib/plugins/xfcedocs/syntax.php |  111 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/lib/plugins/xfcedocs/syntax.php b/lib/plugins/xfcedocs/syntax.php
new file mode 100644
index 0000000..f57c127
--- /dev/null
+++ b/lib/plugins/xfcedocs/syntax.php
@@ -0,0 +1,111 @@
+<?php
+
+if (!defined('DOKU_INC'))
+  define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
+if (!defined('DOKU_PLUGIN'))
+  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
+
+require_once(DOKU_PLUGIN.'syntax.php');
+
+class syntax_plugin_xfcedocs extends DokuWiki_Syntax_Plugin
+{
+    /**
+     * return some info
+     **/
+    function getInfo ()
+    {
+        return array
+        (
+            'author' => 'Nick Schermer',
+            'email'  => 'nick at xfce.org',
+            'date'   => '2011-12-31',
+            'name'   => 'Xfce Syntax Plugin',
+            'desc'   => 'Syntax helpers for the Xfce wikis',
+            'url'    => 'http://git.xfce.org',
+        );
+    }
+
+    /**
+     * What kind of syntax are we?
+     **/
+    function getType ()
+    {
+        return 'substition';
+    }
+
+    /**
+     * Paragraph Type
+     **/
+    function getPType ()
+    {
+        return 'normal';
+    }
+
+    /**
+     * Where to sort in?
+     */
+    function getSort ()
+    {
+        return 10;
+    }
+
+    /**
+     * Connect pattern to lexer
+     */
+    function connectTo ($mode)
+    {
+        $this->Lexer->addSpecialPattern('\{gui\>.*?\}', $mode, 'plugin_xfcedocs');
+        $this->Lexer->addSpecialPattern('\{key\>.*?\}', $mode, 'plugin_xfcedocs');
+        $this->Lexer->addSpecialPattern('\{bug\>\d+\}', $mode, 'plugin_xfcedocs');
+    }
+
+    /**
+     * Handle the match
+     */
+    function handle ($match, $state, $pos, &$handler)
+    {
+        switch ($state)
+        {
+            case DOKU_LEXER_ENTER :
+            case DOKU_LEXER_MATCHED :
+            case DOKU_LEXER_UNMATCHED :
+            case DOKU_LEXER_EXIT :
+                break;
+
+            case DOKU_LEXER_SPECIAL :
+                if (strpos ($match, '{gui>') === 0)
+                    return array('gui', substr ($match, 5, -1));
+                elseif (strpos ($match, '{bug>') === 0)
+                    return array('bug', substr ($match, 5, -1));
+                elseif (strpos ($match, '{key>') === 0)
+                    return array('key', substr ($match, 5, -1));
+        }
+
+        return array();
+    }
+
+    /**
+     * Create output
+     */
+    function render($mode, &$renderer, $data)
+    {
+        if( $mode == 'xhtml')
+        {
+            list ($type, $match) = $data;
+
+            if ($type == 'gui')
+                $renderer->doc .= '<span class="gui"><strong>'. str_replace ('>', '</strong> → <strong>', $match) .'</strong></span>';
+            elseif ($type == 'bug')
+                 $renderer->externallink('https://bugzilla.xfce.org/show_bug.cgi?id='.$match, 'bug #'.$match);
+            elseif ($type == 'key')
+                 $renderer->doc .= '<span class="key"><strong>'. str_replace ('+', '</strong>-<strong>', $match) .'</strong></span>';
+            else
+                 return false;
+
+            return true;
+        }
+        return false;
+    }
+};
+
+?>


More information about the Xfce4-commits mailing list