[Xfce4-commits] <wiki:master> Add figure support to xfcedocs plugin.

Nick Schermer noreply at xfce.org
Wed Jan 4 21:14:01 CET 2012


Updating branch refs/heads/master
         to ab2baa5e8d789f124adac773466b3a988f46968f (commit)
       from 49652cc23dd3c7dbdd288df389d4638eda2f13dc (commit)

commit ab2baa5e8d789f124adac773466b3a988f46968f
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Jan 4 21:10:01 2012 +0100

    Add figure support to xfcedocs plugin.

 lib/plugins/xfcedocs/style.css  |   18 +++++++++
 lib/plugins/xfcedocs/syntax.php |   79 +++++++++++++++++++++++++++++----------
 2 files changed, 77 insertions(+), 20 deletions(-)

diff --git a/lib/plugins/xfcedocs/style.css b/lib/plugins/xfcedocs/style.css
new file mode 100644
index 0000000..8331c24
--- /dev/null
+++ b/lib/plugins/xfcedocs/style.css
@@ -0,0 +1,18 @@
+div.dokuwiki div.figure {
+  background-color: __background__;
+  border: 1px solid __border__;
+  padding: 6px;
+}
+
+div.dokuwiki div.figure-title {
+  text-align: center;
+  font-weight: bold;
+  padding-bottom: 6px;
+}
+
+div.dokuwiki div.figure-contents {
+  text-align: center;
+  border: 1px solid __border__;
+  padding: 6px;
+  background-color: __background_c__;
+}
diff --git a/lib/plugins/xfcedocs/syntax.php b/lib/plugins/xfcedocs/syntax.php
index f57c127..2040035 100644
--- a/lib/plugins/xfcedocs/syntax.php
+++ b/lib/plugins/xfcedocs/syntax.php
@@ -41,6 +41,11 @@ class syntax_plugin_xfcedocs extends DokuWiki_Syntax_Plugin
         return 'normal';
     }
 
+    function getAllowedTypes ()
+    {
+        return array('container','substition','protected','disabled','formatting','paragraphs');
+    }
+
     /**
      * Where to sort in?
      */
@@ -57,6 +62,11 @@ class syntax_plugin_xfcedocs extends DokuWiki_Syntax_Plugin
         $this->Lexer->addSpecialPattern('\{gui\>.*?\}', $mode, 'plugin_xfcedocs');
         $this->Lexer->addSpecialPattern('\{key\>.*?\}', $mode, 'plugin_xfcedocs');
         $this->Lexer->addSpecialPattern('\{bug\>\d+\}', $mode, 'plugin_xfcedocs');
+        $this->Lexer->addEntryPattern('<figure ["\'].*?["\']>(?=.*?</figure>)',$mode,'plugin_xfcedocs');
+    }
+
+    function postConnect() {
+        $this->Lexer->addExitPattern('</figure>','plugin_xfcedocs');
     }
 
     /**
@@ -66,19 +76,24 @@ class syntax_plugin_xfcedocs extends DokuWiki_Syntax_Plugin
     {
         switch ($state)
         {
-            case DOKU_LEXER_ENTER :
-            case DOKU_LEXER_MATCHED :
-            case DOKU_LEXER_UNMATCHED :
-            case DOKU_LEXER_EXIT :
+            case DOKU_LEXER_ENTER:
+                if (strpos ($match, '<figure ') === 0)
+                    return array($state, 'figure', substr ($match, 9, -2));
+                return array($state, $this->default);
+
+            case DOKU_LEXER_MATCHED:
+            case DOKU_LEXER_UNMATCHED:
+            case DOKU_LEXER_EXIT:
+                return array($state, null, $match);
                 break;
 
-            case DOKU_LEXER_SPECIAL :
+            case DOKU_LEXER_SPECIAL:
                 if (strpos ($match, '{gui>') === 0)
-                    return array('gui', substr ($match, 5, -1));
+                    return array($state, 'gui', substr ($match, 5, -1));
                 elseif (strpos ($match, '{bug>') === 0)
-                    return array('bug', substr ($match, 5, -1));
+                    return array($state, 'bug', substr ($match, 5, -1));
                 elseif (strpos ($match, '{key>') === 0)
-                    return array('key', substr ($match, 5, -1));
+                    return array($state, 'key', substr ($match, 5, -1));
         }
 
         return array();
@@ -87,20 +102,44 @@ class syntax_plugin_xfcedocs extends DokuWiki_Syntax_Plugin
     /**
      * Create output
      */
-    function render($mode, &$renderer, $data)
+    function render ($mode, &$renderer, $data)
     {
-        if( $mode == 'xhtml')
+        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;
+            list ($state, $type, $match) = $data;
+            
+            switch ($state)
+            {
+                case DOKU_LEXER_ENTER:
+                    if ($type == 'figure')
+                        $renderer->doc .= '<div class="figure"><div class="figure-title">'. 
+                                          $renderer->_xmlEntities($match) .'</div>'.
+                                          '<div class="figure-contents">';
+                    else
+                        return false;
+                    break;
+                
+                case DOKU_LEXER_EXIT :
+                    $renderer->doc .= '</div></div>';
+                    break;
+                
+                case DOKU_LEXER_UNMATCHED :
+                    $renderer->doc .= $renderer->_xmlEntities($match);
+                    break;
+                
+                case DOKU_LEXER_SPECIAL:
+                    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>';
+                    elseif ($type == 'figure')
+                        $renderer->doc .= '<div class="figure">'. $match .'</div>';
+                    else
+                        return false;
+                    break;
+            }
 
             return true;
         }


More information about the Xfce4-commits mailing list