DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:autonumbering

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:autonumbering [2013-01-18 21:22] – [Known Issues] PatB73plugin:autonumbering [2023-03-07 15:12] (current) – documenting new features 150.254.33.213
Line 2: Line 2:
  
 ---- plugin ---- ---- plugin ----
-description: This plugin allows the use of multiples counters with multiples levels, within the same page. +description: This plugin allows the use of multiples counters with multiples levels, within the same page 
-author     : Patrice Bonneau +author     : Florian Wehner 
-email      : patrice.bonneau@live.ca +email      : florian@whnr.de 
 type       : syntax type       : syntax
-lastupdate : 2012-06-04 +lastupdate : 2023-03-04 
-compatible : 2012-01-25 "Angua", 2012-10-13 "Adora Belle"+compatible : 2012-01-25c "Angua", 2012-10-13 "Adora Belle", 2013-05-10a "Weatherwax", 2017-02-19 "Frusterick Manners"
 depends    :  depends    : 
 conflicts  conflicts 
-similar    : +similar    : dokupp
 tags       : counter, level, numbering tags       : counter, level, numbering
-downloadurl: http://dokudiki-autonumbering-plugin.googlecode.com/files/autonumbering_v1.2.zip+downloadurl: https://github.com/whnr/dokuwiki-plugin-autonumbering/tarball/master 
 +bugtracker : https://github.com/whnr/dokuwiki-plugin-autonumbering/issues 
 +sourcerepo : https://github.com/whnr/dokuwiki-plugin-autonumbering/
 ---- ----
-\\+
 ===== Known Issues ===== ===== Known Issues =====
-This plugin don't works in headlines and this can't be fixed. 
-\\  
-See forum : [[https://forum.dokuwiki.org/thread/9334|forum.dokuwiki.org/thread/9334]] 
  
 +This plugin doesn't work in headlines and this can't be fixed.
 +
 +See forum: [[https://forum.dokuwiki.org/d/9334]]
  
  
 ===== Syntax and Use ===== ===== Syntax and Use =====
  
-=== Base ===+===Base ====
  
-Syntax : ~~#~~ +Syntax: ''%%~~#~~%%'' 
-  * Where ~~#~~ will be replaced by a number, auto incremented, and saved in a common counter.+  * Where ''%%~~#~~%%'' will be replaced by a number, auto incremented, and saved in a common counter.
  
-Example : +Example: 
 <code> <code>
 Example number ~~#~~ Example number ~~#~~
Line 35: Line 37:
 Example number ~~#~~ Example number ~~#~~
 -------------------- --------------------
-Result :+Result:
 Example number 1 Example number 1
 Example number 2 Example number 2
 Example number 3 Example number 3
 </code> </code>
-\\  
  
  
-=== Explicit counter ID ===+===Explicit counter ID ====
  
-Syntax : ~~#@COUNTERID~~ +Syntax: ''%%~~#@COUNTERID~~%%'' 
-  * Where COUNTERID is an alphanumeric identificator, including unserscore, and starting with a @. This allows the use of multiple counters.+  * Where ''COUNTERID'' is an alphanumeric identificator, including underscore, and starting with a ''@''. This allows the use of multiple counters.
  
-Example : +Example: 
 <code> <code>
 First counter = ~~#@ctr_ONE~~ First counter = ~~#@ctr_ONE~~
Line 57: Line 58:
 First counter = ~~#@ctr_ONE~~ First counter = ~~#@ctr_ONE~~
 -------------------- --------------------
-Result :+Result:
 First counter = 1 First counter = 1
 First counter = 2 First counter = 2
Line 65: Line 66:
 First counter = 4 First counter = 4
 </code> </code>
-\\  
  
  
-=== Forced numbering ===+===Forced numbering ====
  
-Syntax : ~~#NUM~~ +Syntax: ''%%~~#NUM~~%%'' 
-  * Where NUM is a positive number that will be the begining of the auto incrementation from there.+  * Where ''NUM'' is a positive number that will be the begining of the auto incrementation from there.
  
-Example : +Example: 
 <code> <code>
 Counter = ~~#~~ Counter = ~~#~~
Line 79: Line 79:
 Counter = ~~#~~ Counter = ~~#~~
 -------------------- --------------------
-Result :+Result:
 Counter = 1 Counter = 1
 Counter = 6 Counter = 6
 Counter = 7 Counter = 7
 </code> </code>
-\\  
  
  
-=== Multiple levels ===+===Multiple levels ====
  
-Syntax : ~~#.#~~ +Syntax: ''%%~~#.#~~%%'' 
-  * Where .# represent a sublevel and can be repeated as much as needed.+  * Where ''.#'' represent a sublevel and can be repeated as much as needed.
  
-Example : +Example:
 <code> <code>
 Level = ~~#~~ Level = ~~#~~
Line 103: Line 102:
 Level = ~~#~~ Level = ~~#~~
 -------------------- --------------------
-Result :+Result:
 Level = 1 Level = 1
 Level = 1.1 Level = 1.1
Line 113: Line 112:
 Level = 2 Level = 2
 </code> </code>
-\\  
  
  
-=== Text level ===+===Text level ====
  
-Syntax : ~~TEXT.#~~ +Syntax: ''%%~~TEXT.#~~%%'' 
-  * Where TEXT is alphabetic (without number) and will be reproduce in the number. Only # is an auto incremented number. +  * Where ''TEXT'' is alphabetic (without number) and will be reproduce in the number. Only ''#'' is an auto incremented number
-  * Note : When using text in a level, it will be implicitly used as counter ID if no counter ID have been set explicitly (see « Explicit counter ID » above). In case of multiple levels with text, they will be concatenated to form a single counter ID. In the example below, the counter ID will be « KungFu ».+  * Up to the first auto incremented numbers, the text will be separated by spaces
 +  * Note: when using text in a level, it will be implicitly used as counter ID if no counter ID have been set explicitly (see [[#Explicit counter ID]] above). In case of multiple levels with text, they will be concatenated to form a single counter ID. In the example below, the counter ID will be "KungFu".
  
-Example 1 : +Example 1: 
 <code> <code>
 ~~Kung.Fu.#~~ ~~Kung.Fu.#~~
 +~~Kung.Fu.#.#~~
 +~~Kung.Fu.#.#~~
 ~~Kung.Fu.#~~ ~~Kung.Fu.#~~
-~~Kung.Fu.#~~+~~Kung.Fu.#.#.#~~ 
 +~~Kung.Fu.#.#.#~~
 -------------------- --------------------
-Result : +Result: 
-Kung.Fu.+Kung Fu 1 
-Kung.Fu.2 +Kung Fu 1.
-Kung.Fu.3+Kung Fu 1.2 
 +Kung Fu 2 
 +Kung Fu 2.1.1 
 +Kung Fu 2.1.2
 </code> </code>
-\\  
  
 +==== CSS styling ====
  
-===== Code =====+The numbers are wrapped with a ''<span class="…">'' tag with two classes: ''autonumberingAll'' and ''autonumbering'' followed by all text-only levels separated by an underscore. For example: 
 +  * ''~~#~~'' becomes ''<span class="autonumberingAll autonumbering">1</span>'' 
 +  * ''~~Kung.Fu.#.#~~'' becomes: \\ ''<span class="autonumberingAll autonumbering_Kung_Fu">Kung Fu 1.1</span>''
  
-<code php ./lib/plugins/autonumbering/syntax.php> +To style thisone may create ''conf/tpl/<template name>/'' directorycreate file ''style.ini'' in the directoryand define there a custom cssfor example
-<?php +<code>[stylesheets
-/** +css/autonumbering.css                 screen</code> 
- * DokuWiki Plugin autonumbering (Syntax Component) +Thenin the ''css/autonumbering.css'' (all path relative to ''conf/tpl/<template name>/''), one may write: 
- * +<code> 
- * @description         :   This plugin allows the use of multiples counters +.autonumbering_Kung_Fu 
-                          with multiples levelswithin the same page. +        
- * +                font-style: italic
- * @syntax (Base)       :   ~~#~~ +                text-decoration: #2b73b7 underline;
-                              --> Where ~~#~~ will be replaced by number, +
-                                  auto incremented, and saved in a common +
-                                  counter. +
- * @syntax (ID)         :   ~~#@COUNTERID~~ +
-                              --> Where COUNTERID is an alphanumeric +
-                                  identificator, including unserscore, +
-                                  and starting with a @. This allows +
-                                  the use of multiple counters. +
- * @syntax (forced)     :   ~~#NUM~~ +
-                              --> Where NUM is a positive number that will +
-                                  be the begining of the auto incrementation +
-                                  from there. +
- * @syntax (multilevel) :   ~~#.#~~ +
-                              --> Where .# represent a sublevel and can be +
-                                  repeated as much as needed. +
- * +
- * @syntax (text)       :   ~~REPORT.EXAMPLE.#~~ +
-                              --> Where only the third level will be an auto +
-                                  incremented number. The first level will +
-                                  be a repeated text. Here it will be REPORT. +
-                                  Samething for the second level with EXAMPLE. +
-                                  When using text in a level, it will be +
-                                  implicitly used as counter ID if no counter +
-                                  ID have been set with @COUNTERID. +
- * +
- * @example             :   ~~Test.#4.#6@CTR_ONE~~ +
-                              --> Where the number will have three levels. +
-                                  First level will be the text « Test ». +
-                                  Second level will be an auto incremented +
-                                  number starting at 4. Third level will be +
-                                  an auto incremented number starting at 6. +
-                                  All this will be save in the counter +
-                                  « CTR_ONE ». +
- * +
- * @license             :   GPL 2 http://www.gnu.org/licenses/gpl-2.0.html +
- * @author              :   Patrice Bonneau <patrice.bonneau@live.ca> +
- * @lastupdate          :   2012-06-12 +
- * @compatible          :   2012-01-25 "Angua" +
- */ +
- +
- +
-// must be run within Dokuwiki +
-if (!defined('DOKU_INC')) die(); +
- +
-if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); +
-if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); +
-if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +
- +
-require_once DOKU_PLUGIN.'syntax.php'; +
- +
-class syntax_plugin_autonumbering extends DokuWiki_Syntax_Plugin { +
- +
-    var $PLUGIN_PATTERN = "~~[a-zA-Z0-9_\.#@]*#[a-zA-Z0-9_\.#@]*~~"; +
-    var $NUMBER_PATTERN = "[0-9]+"; +
-    var $COUNTER_ID_PATTERN = "[a-zA-Z0-9_]+"; +
- +
- +
-    public function getType()    { return 'substition'; } +
-    public function getPType()   { return 'normal';+
-    public function getSort()    { return 45; } +
-    public function getInfo()    { +
-        return array( +
-            'author' => 'Patrice Bonneau', +
-            'email'  => 'patrice.bonneau@live.ca'+
-            'date'   => '2012-06-04', +
-            'name'   => 'Autonumbering Plugin', +
-            'desc'   => 'Allows the use of multiples counters with multiples levelswithin the same page.', +
-            'url'    => 'http://www.dokuwiki.org/plugin:autonumbering', +
-        ); +
-    } +
- +
- +
-    public function connectTo($mode) { +
-        $this->Lexer->addSpecialPattern($this->PLUGIN_PATTERN, $mode, 'plugin_autonumbering'); +
-    } +
- +
- +
-    public function handle($match, $state, $pos, &$handler){ +
-        global $COUNTER; +
-        $counterID = ''; +
-        switch ($state) { +
-            case DOKU_LEXER_SPECIAL : +
- +
-                if (preg_match('/~~(.*?)~~/', $match, $matches)) { +
-                    $data = $matches[1]; +
- +
-                    if (!empty($data)) { +
-                        // Search for EXPLICIT counter ID +
-                        if (preg_match('/@(' $this->COUNTER_ID_PATTERN . ')/', $data, $matches)) { +
-                            $counterID $matches[1]; +
-                            // Remove counter ID from $data +
-                            $data = str_replace('@' . $counterID, '', $data); +
-                        } else {    // Search for IMPLICIT counter ID +
-                            $alpha = preg_replace('/[^a-zA-Z]/', '', $data); +
-                            if (!empty($alpha)) +
-                                $counterID = $alpha; +
-                        } +
- +
-                        // Separate levels +
-                        $dataTab = explode('.', $data); +
- +
-                        // Get levels quantity +
-                        $levelsQty = count($dataTab); +
-                        $currentLevel = $levelsQty - 1; +
- +
-                        // Check if parent level exist +
-                        for ($i = 0; $i $levelsQty; ++$i) { +
-                            // Check if level contain text +
-                            if (ctype_alpha($dataTab[$i])) +
-                                $COUNTER[$counterID][$i] = $dataTab[$i]; +
-                            // Search for a forced value +
-                            else if (preg_match('/(' . $this->NUMBER_PATTERN . ')/'$dataTab[$i], $matches)) +
-                                if ($i == $currentLevel) +
-                                    $COUNTER[$counterID][$i] = $matches[1]-1; +
-                                else +
-                                    $COUNTER[$counterID][$i] = $matches[1]; +
-                            // initialize if needed +
-                            else if ((!isset($COUNTER[$counterID][$i])) || ($COUNTER[$counterID][$i] == 0)) +
-                                if ($i == $currentLevel) +
-                                    $COUNTER[$counterID][$i] = 0; +
-                                else +
-                                    $COUNTER[$counterID][$i] = 1; +
-                        } +
- +
-                        // Check if child level exist, and initialize +
-                        $counter_levelsQty = count($COUNTER[$counterID]); +
-                        for ($i = $currentLevel+1; $i $counter_levelsQty; ++$i) +
-                            $COUNTER[$counterID][$i] = 0; +
- +
-                        // Increment current level +
-                        ++$COUNTER[$counterID][$currentLevel]; +
- +
-                        // Return the number, according the level asked +
-                        $number = ''; +
-                        $period = ''; +
-                        for ($i = 0; $i < $levelsQty; ++$i) { +
-                            $number .= $period . $COUNTER[$counterID][$i]; +
-                            $period = '.'; +
-                        } +
-                        return array($number, NULL); +
-                    } else +
-                        return array($match, NULL); +
-                    } +
-                +
-            break;+
         }         }
-        return array(); +</code> 
-    }+===== FAQ =====
  
-    public function render($mode, &$renderer, $data) { +===== Discussion =====
-        if(($mode == 'xhtml') && (!empty($data))) { +
-            list($number, $null) $data; +
-            $renderer->doc .$number; +
-            return true; +
-        } +
-        return false; +
-    }+
  
- +I republished this plugin as I found it useful. The original code is by [[patrice.bonneau@live.ca|Patrice Bonneau]].
-    // To work with the plugin « reproduce », who needs to do +
-    // the numbering prior to reproducing the code+
-    public function doNumbering($pageContent){ +
-        $qtyOccurrences = preg_match_all('/~~(.*?)~~/', $pageContent, $matches); +
-        if ($qtyOccurrences > 0) { +
-            for ($i = 0; $i < $qtyOccurrences; $i++) { +
-                list($number, $null) = $this->handle($matches[0][$i], DOKU_LEXER_SPECIAL, NULL, $handler); +
-                $pageContent = preg_replace('(' $matches[0][$i] . ')', $number, $pageContent, 1); +
-            } +
-        } +
-        return $pageContent; +
-    } +
-+
-</code>+
plugin/autonumbering.1358540528.txt.gz · Last modified: 2013-01-18 21:22 by PatB73

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki