plugin:autonumbering
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:autonumbering [2012-07-01 23:24] – added file name and path to plugin's code snippet ach | plugin:autonumbering [2023-03-07 15:12] (current) – documenting new features 150.254.33.213 | ||
---|---|---|---|
Line 2: | Line 2: | ||
---- plugin ---- | ---- plugin ---- | ||
- | description: | + | description: |
- | author | + | author |
- | 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 " | + | compatible : 2012-01-25c "Angua", 2012-10-13 "Adora Belle", |
depends | depends | ||
conflicts | conflicts | ||
- | similar | + | similar |
- | tags : | + | tags : counter, level, numbering |
- | downloadurl: | + | downloadurl: |
+ | bugtracker : https:// | ||
+ | sourcerepo : https:// | ||
---- | ---- | ||
- | \\ | + | |
+ | ===== Known Issues ===== | ||
+ | |||
+ | This plugin doesn' | ||
+ | |||
+ | See forum: [[https:// | ||
===== Syntax and Use ===== | ===== Syntax and Use ===== | ||
- | === - Base - === | + | ==== Base ==== |
- | Syntax : ~~#~~ | + | Syntax: |
- | * Where ~~#~~ will be replaced by a number, auto incremented, | + | * Where '' |
- | Example : | + | Example: |
< | < | ||
Example number ~~#~~ | Example number ~~#~~ | ||
Line 30: | 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 | ||
</ | </ | ||
- | \\ | ||
- | === - Explicit counter ID - === | + | ==== Explicit counter ID ==== |
- | Syntax : ~~# | + | Syntax: |
- | * Where COUNTERID is an alphanumeric identificator, | + | * Where '' |
- | Example : | + | Example: |
< | < | ||
First counter = ~~# | First counter = ~~# | ||
Line 52: | Line 58: | ||
First counter = ~~# | First counter = ~~# | ||
-------------------- | -------------------- | ||
- | Result : | + | Result: |
First counter = 1 | First counter = 1 | ||
First counter = 2 | First counter = 2 | ||
Line 60: | Line 66: | ||
First counter = 4 | First counter = 4 | ||
</ | </ | ||
- | \\ | ||
- | === - Forced numbering | + | ==== Forced numbering |
- | Syntax : ~~#NUM~~ | + | Syntax: |
- | * Where NUM is a positive number that will be the begining of the auto incrementation from there. | + | * Where '' |
- | Example : | + | Example: |
< | < | ||
Counter = ~~#~~ | Counter = ~~#~~ | ||
Line 74: | Line 79: | ||
Counter = ~~#~~ | Counter = ~~#~~ | ||
-------------------- | -------------------- | ||
- | Result : | + | Result: |
Counter = 1 | Counter = 1 | ||
Counter = 6 | Counter = 6 | ||
Counter = 7 | Counter = 7 | ||
</ | </ | ||
- | \\ | ||
- | === - Multiple levels | + | ==== Multiple levels |
- | Syntax : ~~#.#~~ | + | Syntax: |
- | * Where .# represent a sublevel and can be repeated as much as needed. | + | * Where '' |
- | Example : | + | Example: |
< | < | ||
Level = ~~#~~ | Level = ~~#~~ | ||
Line 98: | Line 102: | ||
Level = ~~#~~ | Level = ~~#~~ | ||
-------------------- | -------------------- | ||
- | Result : | + | Result: |
Level = 1 | Level = 1 | ||
Level = 1.1 | Level = 1.1 | ||
Line 108: | Line 112: | ||
Level = 2 | Level = 2 | ||
</ | </ | ||
- | \\ | ||
- | === - Text level - === | + | ==== Text level ==== |
- | Syntax : ~~TEXT.# | + | Syntax: |
- | * Where TEXT is alphabetic (without number) and will be reproduce in the number. Only # is an auto incremented number. | + | * Where '' |
- | * 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: |
< | < | ||
~~Kung.Fu.# | ~~Kung.Fu.# | ||
+ | ~~Kung.Fu.# | ||
+ | ~~Kung.Fu.# | ||
~~Kung.Fu.# | ~~Kung.Fu.# | ||
- | ~~Kung.Fu.# | + | ~~Kung.Fu.#.#.#~~ |
+ | ~~Kung.Fu.# | ||
-------------------- | -------------------- | ||
- | Result : | + | Result: |
- | Kung.Fu.1 | + | Kung Fu 1 |
- | Kung.Fu.2 | + | Kung Fu 1.1 |
- | Kung.Fu.3 | + | Kung Fu 1.2 |
+ | Kung Fu 2 | ||
+ | Kung Fu 2.1.1 | ||
+ | Kung Fu 2.1.2 | ||
</ | </ | ||
- | \\ | ||
+ | ==== CSS styling ==== | ||
- | ===== Code ===== | + | The numbers are wrapped with a ''< |
+ | * '' | ||
+ | * '' | ||
- | <code php ./lib/plugins/ | + | To style this, one may create a '' |
- | <?php | + | <code>[stylesheets] |
- | /** | + | css/ |
- | * DokuWiki Plugin autonumbering (Syntax Component) | + | Then, in the '' |
- | * | + | <code> |
- | * @description | + | .autonumbering_Kung_Fu |
- | | + | { |
- | * | + | font-style: italic; |
- | * @syntax (Base) | + | text-decoration: #2b73b7 underline; |
- | | + | } |
- | | + | </code> |
- | | + | ===== FAQ ===== |
- | * @syntax (ID) : ~~# | + | |
- | * --> Where COUNTERID is an alphanumeric | + | |
- | * identificator, | + | |
- | | + | |
- | * | + | |
- | * @syntax | + | |
- | * --> Where NUM is a positive number that will | + | |
- | * be the begining of the auto incrementation | + | |
- | | + | |
- | * @syntax (multilevel) : | + | |
- | * | + | |
- | * repeated as much as needed. | + | |
- | * | + | |
- | * @syntax (text) : | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | * | + | |
- | * @example | + | |
- | * --> Where the number will have three levels. | + | |
- | * First level will be the text « Test ». | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | * | + | |
- | * @license | + | |
- | * @author | + | |
- | * @lastupdate | + | |
- | * @compatible | + | |
- | */ | + | |
+ | ===== Discussion ===== | ||
- | // must be run within Dokuwiki | + | I republished this plugin as I found it useful. The original code is by [[patrice.bonneau@live.ca|Patrice Bonneau]]. |
- | if (!defined(' | + | |
- | + | ||
- | if (!defined(' | + | |
- | if (!defined(' | + | |
- | if (!defined(' | + | |
- | + | ||
- | require_once DOKU_PLUGIN.' | + | |
- | + | ||
- | class syntax_plugin_autonumbering extends DokuWiki_Syntax_Plugin { | + | |
- | + | ||
- | var $PLUGIN_PATTERN = "~~[a-zA-Z0-9_\.# | + | |
- | var $NUMBER_PATTERN = "[0-9]+"; | + | |
- | var $COUNTER_ID_PATTERN = " | + | |
- | + | ||
- | + | ||
- | public function getType() | + | |
- | public function getPType() | + | |
- | public function getSort() | + | |
- | public function getInfo() | + | |
- | return array( | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ); | + | |
- | } | + | |
- | + | ||
- | + | ||
- | public function connectTo($mode) { | + | |
- | $this-> | + | |
- | } | + | |
- | + | ||
- | + | ||
- | public function handle($match, | + | |
- | global $COUNTER; | + | |
- | $counterID = ''; | + | |
- | switch ($state) { | + | |
- | case DOKU_LEXER_SPECIAL : | + | |
- | + | ||
- | if (preg_match('/ | + | |
- | $data = $matches[1]; | + | |
- | + | ||
- | if (!empty($data)) { | + | |
- | // Search for EXPLICIT counter ID | + | |
- | if (preg_match('/ | + | |
- | $counterID = $matches[1]; | + | |
- | // Remove counter ID from $data | + | |
- | $data = str_replace(' | + | |
- | // Search for IMPLICIT counter ID | + | |
- | } else { | + | |
- | $alpha = preg_replace('/ | + | |
- | if (!empty($alpha)) | + | |
- | $counterID = $alpha; | + | |
- | } | + | |
- | + | ||
- | // Separate levels | + | |
- | $dataTab = explode(' | + | |
- | + | ||
- | // Get level quantity | + | |
- | $levelQty = count($dataTab); | + | |
- | $currentLevel = $levelQty - 1; | + | |
- | + | ||
- | // Check if parent level exist | + | |
- | for ($i = 0; $i < $levelQty; ++$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('/ | + | |
- | if ($i == $currentLevel) | + | |
- | $COUNTER[$counterID][$i] = $matches[1]-1; | + | |
- | else | + | |
- | $COUNTER[$counterID][$i] = $matches[1]; | + | |
- | // initialize if needed | + | |
- | else if ((!isset($COUNTER[$counterID][$i])) | + | |
- | if ($i == $currentLevel) | + | |
- | $COUNTER[$counterID][$i] = 0; | + | |
- | else | + | |
- | $COUNTER[$counterID][$i] = 1; | + | |
- | } | + | |
- | + | ||
- | // Check if child level exist, and initialize | + | |
- | $counter_levelQty = count($COUNTER[$counterID]); | + | |
- | for ($i = $currentLevel+1; | + | |
- | $COUNTER[$counterID][$i] = 0; | + | |
- | + | ||
- | // Increment current level | + | |
- | ++$COUNTER[$counterID][$currentLevel]; | + | |
- | + | ||
- | // Return the number, according the level asked | + | |
- | $number = ''; | + | |
- | $period =''; | + | |
- | for ($i = 0; $i < $levelQty; ++$i) { | + | |
- | $number | + | |
- | $period = ' | + | |
- | } | + | |
- | return array($number, | + | |
- | } else { | + | |
- | return array($match, | + | |
- | } | + | |
- | } | + | |
- | break; | + | |
- | } | + | |
- | return array(); | + | |
- | } | + | |
- | + | ||
- | public function render($mode, | + | |
- | if(($mode == ' | + | |
- | list($number, | + | |
- | $renderer-> | + | |
- | return true; | + | |
- | } | + | |
- | return false; | + | |
- | } | + | |
- | } | + | |
- | </ | + |
plugin/autonumbering.1341177885.txt.gz · Last modified: 2012-07-01 23:24 by ach