DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:numberedheadings

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:numberedheadings [2018-05-29 23:35] Klap-inplugin:numberedheadings [2023-09-13 08:34] (current) – update version s-sahara
Line 1: Line 1:
-====== Plugin Numbered Headings ======+====== Numbered Headings Plugin ======
  
 ---- plugin ---- ---- plugin ----
 description: Adds numbered headings to DokuWiki without changing the actual behavior of the standard headings. description: Adds numbered headings to DokuWiki without changing the actual behavior of the standard headings.
-author     : Lars J. Metz +author     : Lars J. Metz, Satoshi Sahara 
-email      : dokuwiki@meistermetz.de+email      : sahara.satoshi@gmail.com
 type       : syntax type       : syntax
-lastupdate : 2010-05-12 +lastupdate : 2023-09-12 
-compatible : 2013-06-032009-12-252014-09-29 "Hrun"2015-08-10 "Detritus"+compatible : 2018-04-222020-07-292022-08-022023-04-04
 depends    : depends    :
 conflicts  : ckgedit, include conflicts  : ckgedit, include
Line 13: Line 13:
 tags       : style, headings tags       : style, headings
  
-downloadurl: http://www.meistermetz.de/numberedheadings.zip+downloadurl: https://github.com/ssahara/dw-plugin-NumberedHeadings/archive/master.zip 
 +bugtracker : https://github.com/ssahara/dw-plugin-NumberedHeadings/issues 
 +sourcerepo : https://github.com/ssahara/dw-plugin-NumberedHeadings 
 ---- ----
  
Line 21: Line 24:
 Alternatively, refer to [[:Plugins]] on how to install plugins manually. Download the plugin package and unpack it to your plugin-directory (**lib/plugins/**). This will create a new folder called **numberedheadings**. Alternatively, refer to [[:Plugins]] on how to install plugins manually. Download the plugin package and unpack it to your plugin-directory (**lib/plugins/**). This will create a new folder called **numberedheadings**.
  
-You may use the following links (at your own risk), these links are provided for convenience to use with the DokuWiki plugin manager: 
-[[http://www.meistermetz.de/numberedheadings.tar.gz|numberedheadings.tar.gz]] (3kB) or [[http://www.meistermetz.de/numberedheadings.zip|numberedheadings.zip]] (4kB) 
  
 ===== Usage ===== ===== Usage =====
  
-To use this plugin just add a '-' between the '=and the actual heading:+Adding "''%%-%%''" before the heading text will make the headings tiered-numbered. You can choose the first-tier level (**tier1**) in the Configuration manager. The **tier1** may be a fixed value (eg. level 2) or auto-detected in the page. You can use "''%%-#<number>%%''" to set number of the heading
   ====== - Level 1 Headline ======   ====== - Level 1 Headline ======
   ===== - Level 2 Headline =====   ===== - Level 2 Headline =====
 +  ==== -#5 Level 3 Headline ====
   ==== - Level 3 Headline ====   ==== - Level 3 Headline ====
 +  ===== -#7 Level 2 Headline =====
   ==== - Level 3 Headline ====   ==== - Level 3 Headline ====
-  ===== - Level 2 Headline ===== 
-  ==== - Level 3 Headline ==== 
-  ... 
-The output should then look like this: 
-  1 Level 1 Headline 
-      1.1 Level 2 Headline 
-          1.1.1 Level 3 Headline 
-          1.1.2 Level 3 Headline 
-      1.2 Level 2 Headline 
-          1.2.1 Level 3 Headline 
-  ... 
  
 +When the config **tier1** is set to 2, the headings are interpreted as if you have written:
 +  ====== Level 1 Headline ======
 +  ===== 1. Level 2 Headline =====
 +  ==== 1.5 Level 3 Headline ====
 +  ==== 1.6 Level 3 Headline ====
 +  ===== 7. Level 2 Headline =====
 +  ==== 7.1 Level 3 Headline ====
 +  
 +=== Experimental: Alpha-numeric numbering ===
  
 +Character variables can be incremented in PHP, like A0, A1, A2 ... You can use ''%%-"<string>"%%'' to set number string of the heading.
  
-The user can also set the outline level with the following markup (Thanks to [[martin@idea-games.com|Martin Klima]]):+  ==== -"A1" Appendix ==== 
 +  === - headline ===
  
-  === - #<number> Heading text === 
  
-For example:+===== Configuration =====
  
-  ====== - #3 Level 1 Headline ====== +The plugin can be configured within the DokuWiki configuration manager available through the admin menu.
-  ===== - Level 2 Headline =====+
  
-will be rendered+^ tier1   | heading level corresponding to the 1st tier | default = **2**((As I use a sidebar-index showing the first heading instead of the filename, I configured the plugin to start with the numbered headings from **H2** on. Otherwise the numbers would be shown in the index... but feel free to change the level to **1**.)) | 
 +^ format  | numbering format (used in vsprintf) of each tier, JSON array string  || 
 +^ fancy   | styled heading numbers | default = **off** |
  
-  3 Level 1 Headline +==== Auto-Detect first-tier level ====
-      3.1 Level 2 Headline+
  
 +When the config **tier1** is ''0'', the heading level where the numbered headings used first in the page will be set as **tier1** value in the page. You can use appropriate 1st-tier level in different pages.
  
-===== Configuration =====+==== Numbering format ====
  
-The plugin can be configured within the DokuWiki configuration manager available through the admin menu.+The config **format** defines tiered numbering style. Each tier format is the formatting string of [[phpfn>sprintf]], must be enclosed in double quotes (''%%"%%''). If //n//-th tier format is not defined, numbers are simply joined with period char. 
 +Some format examples:<file> 
 +["%d.", "%d.%d", "%d.%d.%d", "%d.%d.%d.%d", "%d.%d.%d.%d.%d"
 +["Chapter %d.", "Section %d.%d", "Subsection %d.%d.%d", "(%4$d)"
 +["Model %04d", "%04d-%02d"
 +</file>
  
-^ startlevel | level to start with numbered headings | default **2**((As I use a sidebar-index showing the first heading instead of the filename, I configured the plugin to start with the numbered headings from **H2** on. Otherwise the numbers would be shown in the index... but feel free to change the level to **1**.)) | +==== Control numbering feature ====
-^ tailingdot | show tailing dot after numbers (e.g. 1.2.) | default **0** |+
  
-The example above generates the following output when ''startlevel=2'' ''tailingdot=1'':+The numbered headings that are prefixed with "''%%--%%''" (instead of single "''%%-%%''") are not rendered, but can be used to specify level numbers or tier format.
  
-  Level 1 Headline +<file> 
-      1Level 2 Headline +assume config tier1 is set to 0 
-          1.1. Level 3 Headline +=== --#1000 ["(%04d)"] ===   ... set number and tier format of the level, invisible  
-          1.2Level 3 Headline +=== - item ===    → (1001) item 
-      2Level 2 Headline +=== -- ===             ... initialize tier1, format, headings counter 
-          2.1. Level 3 Headline +==== - item ====  → 1. item 2 
-  ...+</file>
  
-You can also override the startlevel in a per-page basis (Thanks to mat). Just insert this code to your page:(({ {header>n}} will still work fine, but "startlevel" is more speaking))+You can also override the first-tier level in a per-page basis. Just insert this code to your page:
 <code> <code>
-{{startlevel>n}}+~~HEADLINE NUMBERING FIRST LEVEL = n~~
 </code> </code>
  
Line 85: Line 93:
  
  
-===== Code =====+===== Development =====
  
-This is the actual plugin-code.+The Numbered Headings plugin was initially developed by [[dokuwiki@meistermetz.de|Lars J. Metz]], and provided provided for convenience to use with the DokuWiki plugin manager: 
 +[[http://www.meistermetz.de/numberedheadings.tar.gz|numberedheadings.tar.gz]] (3kB) or [[http://www.meistermetz.de/numberedheadings.zip|numberedheadings.zip]] (4kB)
  
-==== lib/plugins/numberedheadings/syntax.php ====+Since 2019-01-02, the plugin code has moved to github repository to provide better accessibility for install and further development opportunity. Thanks Lars J. Metz for your early work and encouraging me to move the code to github.  --- [[user>s.sahara|s.sahara]] //2019-01-02 03:40//
  
-<file php syntax.php> 
-<?php 
-/** 
- * Plugin Numbered Headings: Plugin to add numbered headings to DokuWiki-Syntax 
- * 
- * Usage:   ====== - Heading Level 1====== 
-          ===== - Heading Level 2 ===== 
-          ===== - Heading Level 2 ===== 
-                   ... 
- * 
- * =>       1 Heading Level 1 
-              1.1 Heading Level 2 
-              1.2 Heading Level 2 
-          ... 
- * 
- * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) 
- * @author     Lars J. Metz <dokuwiki@meistermetz.de> 
- */ 
  
-if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +=== Change Log from github repository ===
-if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +
-require_once(DOKU_PLUGIN.'syntax.php');+
  
-class syntax_plugin_numberedheadings extends DokuWiki_Syntax_Plugin {+{{rss>https://github.com/ssahara/dw-plugin-NumberedHeadings/commits/master.atom date 5}}
  
-    // is now set in configuration manager 
-    var $startlevel = 0; // level to start with numbered headings (default = 2) 
-    var $tailingdot = 0; // show a tailing dot after numbers (default = 0) 
  
-    var $levels = array( '======'=>1, +=== Old Revision List ===
-                         '====='=>2, +
-                         '===='=>3, +
-                         '==='=>4, +
-                         '=='=>5); +
- +
-    var $headingCount = +
-                 array(  1=>0, +
-                         2=>0, +
-                         3=>0, +
-                         4=>0, +
-                         5=>0); +
- +
-    function syntax_plugin_numberedheadings() { +
-        $this->startlevel = $this->getConf('startlevel'); +
-        $this->tailingdot = $this->getConf('tailingdot'); +
-    } +
- +
-    function getInfo(){ +
-        return array( 'author' => 'Lars J. Metz', +
-                      'email'  => 'dokuwiki@meistermetz.de', +
-                      'date'   => '2010-05-12', +
-                      'name'   => 'Plugin: Numbered Headings', +
-                      'desc'   => 'Adds numbered headings to DokuWiki', +
-                      'url'    => 'http://www.dokuwiki.org/plugin:NumberedHeadings'); +
-    } +
- +
-    function getType(){ +
-        return 'substition'; +
-    } +
- +
-    function connectTo($mode) { +
-        $this->Lexer->addSpecialPattern( '{{header>[1-5]}}', +
-                                         $mode, +
-                                         'plugin_numberedheadings'); +
-        // added new parameter (matches the parameter name for better recognition) +
-        $this->Lexer->addSpecialPattern( '{{startlevel>[1-5]}}', +
-                                         $mode, +
-                                         'plugin_numberedheadings'); +
-        $this->Lexer->addSpecialPattern( '^[ \t]*={2,6}\s?\-[^\n]+={2,6}[ \t]*(?=\n)', +
-                                         $mode, +
-                                         'plugin_numberedheadings'); +
-    } +
- +
-    function getSort() { +
-        return 45; +
-    } +
- +
-    function handle($match, $state, $pos, Doku_Handler $handler){ +
- +
-        // obtain the startlevel from the page if defined +
-        if (preg_match('/{{[a-z]{6,10}>([1-5]+)}}/', $match, $startlevel)) { +
-            $this->startlevel = $startlevel[1]; +
-            return true; +
-        } +
- +
-        // define the level of the heading +
-        preg_match('/(={2,})/', $match, $heading); +
-        $level = $this->levels[$heading[1]]; +
- +
-        // obtain the startnumber if defined +
-        if (preg_match('/#([0-9]+)\s/', $match, $startnumber) && ($startnumber[1]) > 0) { +
-            $this->headingCount[$level] = $startnumber[1]; +
- +
-            //delete the startnumber-setting markup from string +
-            $match = preg_replace('/#[0-9]+\s/', ' ', $match); +
- +
-        } else { +
- +
-            // increment the number of the heading +
-            $this->headingCount[$level]++; +
-        } +
- +
-        // build the actual number +
-        $headingNumber = ''; +
-        for ($i=$this->startlevel;$i<=5;$i++) { +
- +
-            // reset the number of the subheadings +
-            if ($i>$level) { +
-                $this->headingCount[$i] = 0; +
-            } +
- +
-            // build the number of the heading +
-            $headingNumber .= ($this->headingCount[$i]!=0) ? $this->headingCount[$i].'.' : ''; +
-        } +
- +
-        // delete the tailing dot if wished (default) +
-        $headingNumber = ($this->tailingdot) ? $headingNumber : substr($headingNumber,0,-1); +
- +
-        // insert the number... +
-        $match = preg_replace('/(={2,}\s?)\-/', '${1}'.$headingNumber, $match); +
- +
-        // ... and return to original behavior +
-        $handler->header($match, $state, $pos); +
- +
-        return true; +
-    } +
- +
-    function render($format, Doku_Renderer $renderer, $data) { +
-        //do nothing (already done by original render-method) +
-    } +
-+
-//Setup VIM: ex: et ts=4 enc=utf-8 :</file> +
- +
- +
- --- [[user>Juergen_aus_Zuendorf|Juergen_aus_Zuendorf]] //2018-02-06 16:40//\\ +
--> Changes for compatibility to PHP7: \\  +
-"&$handler" and "&$renderer" to "Doku_Handler $handler" and "Doku_Renderer $renderer" +
-==== lib/plugins/numberedheadings/conf/default.php ==== +
- +
-<file php default.php> +
-<?php +
-/** +
- * Options for the NumberedHeading Plugin +
- * +
- * @author     Lars J. Metz <dokuwiki@meistermetz.de> +
- */ +
- +
-$conf['startlevel'] = 2;  // level to start with numbered headings +
-$conf['tailingdot'] = 0;  // show a tailing dot after the numbers +
-</file> +
- +
-==== lib/plugins/numberedheadings/conf/metadata.php ==== +
- +
-<file php metadata.php> +
-<?php +
-/** +
- * Metadata for the NumberedHeading Plugin +
- * +
- * @author     Lars J. Metz <dokuwiki@meistermetz.de> +
- */ +
- +
-$meta['startlevel'] = array('multichoice', '_choices' => array(1, 2 ,3, 4, 5)); +
-$meta['tailingdot'] = array('onoff'); +
-</file> +
- +
-==== lib/plugins/numberedheadings/lang/de/settings.php ==== +
- +
-<file php settings.php> +
-<?php +
-/** +
- * German language file +
- * +
- * @author       Lars J. Metz <dokuwiki@meistermetz.de> +
- */ +
- +
-// for the configuration manager +
-$lang['startlevel'] = 'Nummerierung der Ãœberschriften ab Level beginnen'; +
-$lang['tailingdot'] = 'Punkt nach letzter Zahl anzeigen (z.B. 1.2.)'; +
-</file> +
- +
-==== lib/plugins/numberedheadings/lang/en/settings.php ==== +
- +
-<file php settings.php> +
-<?php +
-/** +
- * English language file +
- * +
- * @author     <dokuwiki@meistermetz.de> +
- */ +
- +
-// for the configuration manager +
-$lang['startlevel'] = 'level to start with numbered headings'; +
-$lang['tailingdot'] = 'show tailing dot after numbers (e.g. 1.2.)'; +
-</file> +
- +
-===== Revision List =====+
  
   * 2006-08-25 --- Published Plugin   * 2006-08-25 --- Published Plugin
Line 292: Line 112:
   * 2010-05-11 --- Added the availability to show a tailingdot   * 2010-05-11 --- Added the availability to show a tailingdot
   * 2010-05-12 --- Brought ''startlevel'' and ''tailingdot'' out to configuration (refactored the code)   * 2010-05-12 --- Brought ''startlevel'' and ''tailingdot'' out to configuration (refactored the code)
 +  * 2019-01-02 --- Added new macro to set startlevel in a page
 +  * 2019-01-03 --- Allow css for tiered numbers in headings
  
  
-===== Discussion =====+===== Tips =====
  
-Feel free to make any comments regarding my plugin... or write me an email ([[dokuwiki@meistermetz.de|Lars J. Metz]]).+For your information: I just wrote [[tips:numbered_headings|a different approach for numbered headings (per CSS)]]. --- //[[a.c.henke@arcor.de|Anika Henke]] 2008-01-06 16:02//
  
-This is so basic, it should be in the basic installation of DokuWiki IMHO... diftong@gmx.net+----
  
-Would be good to bring the start level out to configuration. 
  
-> Done.  --- //[[dokuwiki@meistermetz.de|Lars J. Metz]] 2010/05/12 17:50// +===== Old Discussion =====
- +
-----+
  
 Could a similar system be used to format the numbered lists in nested decimal style instead of the crazy roman numerals and stuff? Better with just changing the css maybe? If so any ideas how best to do that?  Armin. Could a similar system be used to format the numbered lists in nested decimal style instead of the crazy roman numerals and stuff? Better with just changing the css maybe? If so any ideas how best to do that?  Armin.
  
 ---- ----
- 
  
 Great thing, just what I was looking for, there is just one issue in combination with page-includes ([[plugin:include]]), they are not renumbered correctly, for each include page they start with 1. The same for headlines in the original page. //2006-09-19 23:31 [[loco@tag-am-meer.info|Dirk 'el loco' Haage]]// Great thing, just what I was looking for, there is just one issue in combination with page-includes ([[plugin:include]]), they are not renumbered correctly, for each include page they start with 1. The same for headlines in the original page. //2006-09-19 23:31 [[loco@tag-am-meer.info|Dirk 'el loco' Haage]]//
Line 326: Line 144:
 ---- ----
  
-For your information: I just wrote [[tips:numbered_headings|a different approach for numbered headings (per CSS)]]. --- //[[a.c.henke@arcor.de|Anika Henke]] 2008-01-06 16:02//+Seems like the changes in Rincewind metadata handling means that the numbering sometimes doesn't start from 0 anymore. Any plans to update for the official new release? - // Senorandy 2011/05/03 11:01 //
  
 ---- ----
  
-** Per page start level **+==== Per page start level ====
  
 I've just merged the code for adding the ability to set  the startlevel in a per-page basis. Just added the first line of ''connectTo'' and the first ''if'' in ''handle''. I've just merged the code for adding the ability to set  the startlevel in a per-page basis. Just added the first line of ''connectTo'' and the first ''if'' in ''handle''.
- +Also, added the instructions for using. --- //mat, 2008-09-04//
-Also, added the instructions for using. +
- +
---- //mat, 04-09-08//+
  
 > Thanks  --- //[[dokuwiki@meistermetz.de|Lars J. Metz]] 2010/05/12 18:08// > Thanks  --- //[[dokuwiki@meistermetz.de|Lars J. Metz]] 2010/05/12 18:08//
  
 ---- ----
 +
 +==== Set outline level for each heading ====
  
 I have added the ability for the user to set the outline level with the following markup: I have added the ability for the user to set the outline level with the following markup:
Line 361: Line 178:
  
 ---- ----
 +
 +==== Css for heading numbers ====
 +
 +**Fantastic plugin!** I was wondering if anyone knows what I would need to modify to add tags like <code><span></span></code> around the heading numbers. This would allow them to be differently styled, positioned, and even do cool things like section numbering outside the margins of printed documents (what I'm trying to do.)
 +
 +I have tried messing with the code myself, but any html I add shows as text, and not interpreted as real html code. Could anyone figure this out? - // [[kououken@gmail.com|kououken]] 2012/02/07 14:32 //
 +
 +----
 +===== Suggestion / Request =====
 +
 +> **Great plugin**  - Can I make a request to:
 +>   - Include an option by wiki, to do this automatically (without the hyphens) for all pages
 +>     - Disable option by page, when enabled at wiki level
 +>   - Enable the option by page by a setting at the top of the page
 +
 +> Thanks!
 +
 +I just developed this feature for my own needs. The code is available from [[https://github.com/albinou/numberedheadings]]. Feedbacks are welcome. So this version adds:
 +  * an option to enable numbering by default on every page
 +  * the possibility to use ''<nowiki>{{enable_numbering}}</nowiki>'' or ''<nowiki>{{disable_numbering}}</nowiki>''
 +
 +
 +==== Start pages with sub level ====
 +
 +I would like to break up longer pages into subpages. These new pages then should to start numbering at a sub level.
 +
 +For example:
 +
 +  ====== - #3.1 Level 1 Headline ======
 +  ===== - Level 2 Headline =====
 +
 +should be rendered as:
 +
 +  3.1 Level 1 Headline
 +      3.1.1 Level 2 Headline
 +
 +What changes to ''syntax.php'' would be necessary in order to accomplish that?
 +
 +----
 +
 +==== More flexible numbering ====
  
 Some modification. For example: Some modification. For example:
Line 399: Line 257:
  --- //[[lainme993@gmail.com|lainme]] 2010/06/20 03:24//  --- //[[lainme993@gmail.com|lainme]] 2010/06/20 03:24//
  
----- 
  
-Seems like the changes in Rincewind metadata handling means that the numbering sometimes doesn't start from 0 anymore. Any plans to update for the official new release? - // Senorandy 2011/05/03 11:01 // 
- 
----- 
- 
-**Fantastic plugin!** I was wondering if anyone knows what I would need to modify to add tags like <code><span></span></code> around the heading numbers. This would allow them to be differently styled, positioned, and even do cool things like section numbering outside the margins of printed documents (what I'm trying to do.) 
- 
-I have tried messing with the code myself, but any html I add shows as text, and not interpreted as real html code. Could anyone figure this out? - // [[kououken@gmail.com|kououken]] 2012/02/07 14:32 // 
- 
----- 
-===== Suggestion / Request ===== 
-> **Great plugin**  - Can I make a request to: 
->   - Include an option by wiki, to do this automatically (without the hyphens) for all pages 
->     - Disable option by page, when enabled at wiki level 
->   - Enable the option by page by a setting at the top of the page 
- 
-> Thanks! 
- 
-I just developed this feature for my own needs. The code is available for download [[https://github.com/albinou/numberedheadings/archive/master.zip|here]]. Feedbacks are welcome. So this version adds: 
-  * an option to enable numbering by default on every page 
-  * the possibility to use ''<nowiki>{{enable_numbering}}</nowiki>'' or ''<nowiki>{{disable_numbering}}</nowiki>'' 
- 
-===== Frusterick Manners: frustrating problem ===== 
-It is so nice, but: 
- 
-Warning: Declaration of syntax_plugin_numberedheadings::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /www/htdocs/wxxxxx/xxxxx.de/dokuwiki/lib/plugins/numberedheadings/syntax.php on line 130 
- 
-Warning: Declaration of syntax_plugin_numberedheadings::render($format, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /www/htdocs/wxxxxx/xxxxx.de/dokuwiki/lib/plugins/numberedheadings/syntax.php on line 130 
- 
-Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/wxxxxx/xxxxx.de/dokuwiki/lib/plugins/numberedheadings/syntax.php:130) in /www/htdocs/wxxxxx/xxxxx.de/dokuwiki/inc/actions.php on line 210 
- 
-Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/wxxxxx/xxxxx.de/dokuwiki/lib/plugins/numberedheadings/syntax.php:130) in /www/htdocs/wxxxxx/xxxxx.de/dokuwiki/lib/tpl/dokuwiki/main.php on line 12 
- 
-Only with the downloaded version are these problems, the version of the syntax.php shown here seems to be updated and ok: 
-Doku_Handler $handler; 
-Doku_Renderer $renderer; are the trouble preventers. 
-  
plugin/numberedheadings.1527629742.txt.gz · Last modified: 2018-05-29 23:35 by Klap-in

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