plugin:inlinetoc
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:inlinetoc [2013-07-27 22:38] – [inlinetoc.js jQuery version for Adora Belle and Weatherwax] Andreone | plugin:inlinetoc [2018-06-04 22:40] (current) – [Installation] Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
---- plugin ---- | ---- plugin ---- | ||
- | description: | + | description: |
author | author | ||
email : nfauvet@free.fr | email : nfauvet@free.fr | ||
type : syntax, action | type : syntax, action | ||
- | lastupdate : 2013-07-27 | + | lastupdate : 2015-06-19 |
- | compatible : 2010-11-07, 2011-05-25, Angua, Adora Belle, Weatherwax | + | compatible : 2010-11-07, 2011-05-25, Angua, Adora Belle, Weatherwax, Hrun |
depends | depends | ||
conflicts | conflicts | ||
- | similar | + | similar |
tags : toc, mediawiki | tags : toc, mediawiki | ||
- | downloadurl: | + | downloadurl: |
- | bugtracker : http:// | + | bugtracker : https:// |
- | sourcerepo : http:// | + | sourcerepo : https:// |
donationurl: | donationurl: | ||
---- | ---- | ||
Line 21: | Line 21: | ||
===== Installation ===== | ===== Installation ===== | ||
- | Install | + | Search and install |
===== Examples/ | ===== Examples/ | ||
Line 29: | Line 29: | ||
Sample result: | Sample result: | ||
- | {{https:// | + | {{https:// |
===== Notes ===== | ===== Notes ===== | ||
Line 39: | Line 39: | ||
===== Change Log ===== | ===== Change Log ===== | ||
+ | * **2015-06-19** | ||
+ | * merge pull request | ||
+ | * Set PType to avoid an open ' | ||
+ | * Use DokuWikis way to disable the original TOC | ||
* **2013-07-27** | * **2013-07-27** | ||
* fixed to work with recent versions of Dokuwiki - cf [[https:// | * fixed to work with recent versions of Dokuwiki - cf [[https:// | ||
Line 50: | Line 54: | ||
* **2011-05-30** | * **2011-05-30** | ||
* Initial release | * Initial release | ||
+ | |||
===== Wishes ===== | ===== Wishes ===== | ||
+ | |||
- Can this plugin be enabled for whole wiki?\\ Not really because it's built as a replacement plugin, not a general purpose plugin. It could be adapted but I believe it would make more sense to make a completely separate plugin for that purpose. < | - Can this plugin be enabled for whole wiki?\\ Not really because it's built as a replacement plugin, not a general purpose plugin. It could be adapted but I believe it would make more sense to make a completely separate plugin for that purpose. < | ||
- Could it be possible to limit the displayed level of headings?\\ e.g. '' | - Could it be possible to limit the displayed level of headings?\\ e.g. '' | ||
+ | |||
+ | ===== Improvements ===== | ||
+ | |||
+ | This improvement allows to create multiple tocs inside of the document (different deeps and start points) | ||
+ | |||
+ | ==== Syntax ==== | ||
+ | |||
+ | < | ||
+ | => normal inlinetoc as you know | ||
+ | < | ||
+ | => inlinetoc beginning at current header(namespace in document) | ||
+ | < | ||
+ | => inlinetoc beginning at specified header(namespace in document) | ||
+ | < | ||
+ | => normal inlinetoc with endlevel (deep) of 1 | ||
+ | < | ||
+ | => inlinetoc beginning at current header(namespace in document) with endlevel (deep) of 1 | ||
+ | |||
+ | ==== Code ==== | ||
+ | |||
+ | <file php action.php> | ||
+ | <?php | ||
+ | /** | ||
+ | * InlineTOC-Plugin: | ||
+ | * | ||
+ | * @license GPL v2 (http:// | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | |||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | class action_plugin_inlinetoc extends DokuWiki_Action_Plugin { | ||
+ | |||
+ | /** | ||
+ | * Register event handlers | ||
+ | */ | ||
+ | function register(& | ||
+ | $controller-> | ||
+ | $controller-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Replace our placeholder with the actual toc content | ||
+ | */ | ||
+ | function handle_renderer_content_postprocess(& | ||
+ | { | ||
+ | global $TOC; | ||
+ | if ($TOC) | ||
+ | { | ||
+ | |||
+ | dbglog($event-> | ||
+ | |||
+ | $KEY_WORD = '< | ||
+ | $KEY_WORD_END = ' | ||
+ | |||
+ | // find first toc entry | ||
+ | $pos = strpos($event-> | ||
+ | $pos_end = strpos($event-> | ||
+ | |||
+ | // as long tocs found | ||
+ | while ($pos > 0) | ||
+ | { | ||
+ | $TOC2=$TOC; | ||
+ | |||
+ | // get arguments for toc | ||
+ | $begin_level | ||
+ | $end_level | ||
+ | $autons | ||
+ | $namespace | ||
+ | |||
+ | $match = substr($event-> | ||
+ | $spacer | ||
+ | |||
+ | $param_ans = ' | ||
+ | $param_ns | ||
+ | $param_bl | ||
+ | $param_el | ||
+ | |||
+ | if ($spacer > 0 ) // check if contains parmeters | ||
+ | { | ||
+ | $param_string | ||
+ | $params | ||
+ | |||
+ | foreach ($params as & | ||
+ | { | ||
+ | dbglog(" | ||
+ | |||
+ | if ($param_ans === substr($param, | ||
+ | { | ||
+ | $autons = intval(substr($param, | ||
+ | } | ||
+ | else if ($param_ns === substr($param, | ||
+ | { | ||
+ | $namespace = substr($param, | ||
+ | } | ||
+ | else if ($param_bl === substr($param, | ||
+ | { | ||
+ | $begin_level = intval(substr($param, | ||
+ | } | ||
+ | else if ($param_el === substr($param, | ||
+ | { | ||
+ | $end_level = intval(substr($param, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | dbglog(" | ||
+ | dbglog(" | ||
+ | dbglog(" | ||
+ | dbglog(" | ||
+ | } | ||
+ | |||
+ | $head_level = 0; | ||
+ | $head_id = ''; | ||
+ | |||
+ | // check if we use the auto head namepsace function | ||
+ | if ($autons == 1) | ||
+ | { | ||
+ | |||
+ | // search for previours head | ||
+ | $head = strrpos($event-> | ||
+ | |||
+ | // check if head found | ||
+ | if ($head) | ||
+ | { | ||
+ | // find id | ||
+ | $head_id_key_start = strpos($event-> | ||
+ | $head_id_key_fin = strpos($event-> | ||
+ | $head_id = substr($event-> | ||
+ | |||
+ | dbglog(" | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | $head_id = $namespace; | ||
+ | } | ||
+ | |||
+ | // check if head namespace selected | ||
+ | if ($head_id == '' | ||
+ | { | ||
+ | $in_section = true; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | $in_section = false; | ||
+ | } | ||
+ | |||
+ | foreach ($TOC2 as & | ||
+ | { | ||
+ | |||
+ | $element_level = intval($element[' | ||
+ | $element_id = substr($element[' | ||
+ | |||
+ | dbglog(" | ||
+ | |||
+ | // check if its the head | ||
+ | if ($element_id == $head_id) | ||
+ | { | ||
+ | $in_section = true; | ||
+ | $head_level = $element_level; | ||
+ | |||
+ | unset($TOC2[array_search($element, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // check if outside of head level | ||
+ | if ($element_level <= $head_level) | ||
+ | { | ||
+ | $in_section = false; | ||
+ | } | ||
+ | |||
+ | // filter begin level | ||
+ | if ($element_level < $head_level + $begin_level) | ||
+ | { | ||
+ | unset($TOC2[array_search($element, | ||
+ | } | ||
+ | |||
+ | // filter end level relative to head level | ||
+ | if ($end_level > 0 and $element_level > $end_level + $head_level) | ||
+ | { | ||
+ | unset($TOC2[array_search($element, | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | if (!$in_section) | ||
+ | { | ||
+ | unset($TOC2[array_search($element, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | // | ||
+ | $element[' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // remove unselected | ||
+ | $TOC2 = array_values($TOC2); | ||
+ | |||
+ | // build html toc | ||
+ | $html = '< | ||
+ | |||
+ | // replace placeholder | ||
+ | $event-> | ||
+ | |||
+ | // get next pos | ||
+ | $pos = strpos($event-> | ||
+ | $pos_end = strpos($event-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | /** | ||
+ | * Include javascript | ||
+ | */ | ||
+ | function handle_tpl_metaheader_output(& | ||
+ | $event-> | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Callback for html_buildlist. | ||
+ | * Builds list items with inlinetoc2 printable class instead of dokuwiki' | ||
+ | */ | ||
+ | function html_list_inlinetoc2($item){ | ||
+ | | ||
+ | $link = '#' | ||
+ | }else{ | ||
+ | $link = $item[' | ||
+ | } | ||
+ | |||
+ | return '< | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | <file php syntax.php> | ||
+ | <?php | ||
+ | /** | ||
+ | * InlineTOC-Plugin: | ||
+ | * | ||
+ | * @license GPL v2 (http:// | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | if (!defined(' | ||
+ | require_once(DOKU_INC . ' | ||
+ | if (!defined(' | ||
+ | require_once(DOKU_PLUGIN . ' | ||
+ | |||
+ | class syntax_plugin_inlinetoc extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | */ | ||
+ | function getType() { | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? (took the same as for ~~NOTOC~~) | ||
+ | */ | ||
+ | function getSort() { | ||
+ | return 30; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | */ | ||
+ | function connectTo($mode) { | ||
+ | // to keep compatible to old dokuwiki pages | ||
+ | $this-> | ||
+ | | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | |||
+ | function handle($match, | ||
+ | { | ||
+ | |||
+ | $begin_level = -1; | ||
+ | $end_level = -1; | ||
+ | $autons = false; | ||
+ | $namespace = ''; | ||
+ | |||
+ | |||
+ | $spacer = strpos($match, | ||
+ | |||
+ | $param_ns = ' | ||
+ | $param_bl = ' | ||
+ | $param_el = ' | ||
+ | |||
+ | |||
+ | if ($spacer > 0 ) // check if contains parmeters | ||
+ | { | ||
+ | $param_string = preg_split('/>/ | ||
+ | $params = preg_split('/ | ||
+ | |||
+ | foreach($params as & | ||
+ | { | ||
+ | dbglog(" | ||
+ | |||
+ | if ($param_ns === substr($param, | ||
+ | { | ||
+ | dbglog(" | ||
+ | $namespace = substr($param, | ||
+ | |||
+ | if ($namespace === false or $namespace === '' | ||
+ | { | ||
+ | dbglog(" | ||
+ | $autons = true; | ||
+ | } | ||
+ | |||
+ | dbglog(" | ||
+ | } | ||
+ | else if ($param_bl === substr($param, | ||
+ | { | ||
+ | dbglog(" | ||
+ | $begin = intval(substr($param, | ||
+ | } | ||
+ | else if ($param_el === substr($param, | ||
+ | { | ||
+ | dbglog(" | ||
+ | $end = intval(substr($param, | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | dbglog($namespace, | ||
+ | | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Add placeholder to cached page (will be replaced by action component) | ||
+ | */ | ||
+ | function render($mode, | ||
+ | { | ||
+ | dbglog($data, | ||
+ | | ||
+ | $begin_level = $data[' | ||
+ | $end_level = $data[' | ||
+ | $autons = $data[' | ||
+ | $namespace = $data[' | ||
+ | |||
+ | $renderer-> | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== About ==== | ||
+ | |||
+ | We have needed this functions in our company for internal documentation and it would be nice to see those features in your next release. | ||
+ | |||
+ | Best regards and thanks for your work, | ||
+ | --- [[user> | ||
+ | |||
===== Discussion ===== | ===== Discussion ===== | ||
Line 66: | Line 445: | ||
==== Hiding Dokuwiki TOC for Adora Belle ==== | ==== Hiding Dokuwiki TOC for Adora Belle ==== | ||
+ | |||
Until the plugin is updated, here is what you'll have to change in order to hide the Dokuwiki TOC. Edit inlinetoc.js: | Until the plugin is updated, here is what you'll have to change in order to hide the Dokuwiki TOC. Edit inlinetoc.js: | ||
Line 77: | Line 457: | ||
==== inlinetoc.js jQuery version for Adora Belle and Weatherwax (solved) ==== | ==== inlinetoc.js jQuery version for Adora Belle and Weatherwax (solved) ==== | ||
+ | |||
Here is a jQuery solution to make DokuWiki TOC invisible. | Here is a jQuery solution to make DokuWiki TOC invisible. | ||
Line 96: | Line 477: | ||
>Thank you both of you for providing a working solution during my coma. -- [[user> | >Thank you both of you for providing a working solution during my coma. -- [[user> | ||
+ | |||
==== Problem: no output on screen, INLINETOC not working? (solved) ==== | ==== Problem: no output on screen, INLINETOC not working? (solved) ==== | ||
+ | |||
I inserted < | I inserted < | ||
Any idea would goes wrong? | Any idea would goes wrong? | ||
Line 111: | Line 494: | ||
**not working** | **not working** | ||
< | < | ||
+ | |||
====== plugin inlinetoc ====== | ====== plugin inlinetoc ====== | ||
Line 164: | Line 548: | ||
==== Disabling numbering (solved) ==== | ==== Disabling numbering (solved) ==== | ||
- | I use the [[http:// | + | |
+ | I use the [[plugin: | ||
In print output, INLINETOC also numbers the headings (first number): | In print output, INLINETOC also numbers the headings (first number): | ||
+ | |||
< | < | ||
1. Header 1 | 1. Header 1 | ||
Line 175: | Line 561: | ||
etc. | etc. | ||
</ | </ | ||
+ | |||
On screen, a bullet point is shown. | On screen, a bullet point is shown. | ||
Line 186: | Line 573: | ||
_margin-left: | _margin-left: | ||
} | } | ||
+ | |||
</ | </ | ||
+ | |||
+ | > **Solved 2015-05-14 / Skyscraper** disable list-style-type - edit file dokuwiki/ | ||
+ | < | ||
+ | change from | ||
+ | |||
+ | div.inlinetoc2 ul { | ||
+ | list-style-type: | ||
+ | line-height: | ||
+ | _margin-left: | ||
+ | } | ||
+ | |||
+ | to | ||
+ | |||
+ | div.inlinetoc2 ul { | ||
+ | list-style-type: | ||
+ | line-height: | ||
+ | _margin-left: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Bootstrap3 template ==== | ||
+ | < | ||
+ | |||
+ | Bootstrap3 template [[https:// | ||
+ | |||
+ | --- [[user> |
plugin/inlinetoc.1374957531.txt.gz · Last modified: 2013-07-27 22:38 by Andreone