DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:hiddenheader

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
Last revisionBoth sides next revision
plugin:hiddenheader [2015-08-10 14:40] ziothplugin:hiddenheader [2023-12-29 19:07] zioth
Line 1: Line 1:
 ====== hiddenheader Plugin ====== ====== hiddenheader Plugin ======
- 
  
 ---- plugin ---- ---- plugin ----
Line 7: Line 6:
 email      : elifenton@this_is_not_a_real_email.fake email      : elifenton@this_is_not_a_real_email.fake
 type       : action type       : action
-lastupdate : 2013-05-22 +lastupdate : 2018-12-31 
-compatible : angua, rincewind, weatherwax, detritus+compatible : angua, rincewind, weatherwax, binky, ponder stibbons, hrun, detritus, Frusterick Manners, greebo, Hogfather, Igor, Jack Jackrum
 depends    :  depends    : 
 conflicts  conflicts 
Line 14: Line 13:
 tags       : section, header, include, title tags       : section, header, include, title
  
-downloadurl: # eg. http://github.com/zioth/dokuwiki-plugin-hiddenheader/zipball/master +downloadurl: https://github.com/zioth/dokuwiki_hiddenheader/archive/master.zip 
-bugtracker : # eg. http://github.com/zioth/dokuwiki-plugin-hiddenheader/issues +bugtracker : https://github.com/zioth/dokuwiki_hiddenheader/issues 
-sourcerepo : # eg. http://github.com/zioth/dokuwiki-plugin-hiddenheader/+sourcerepo : https://github.com/zioth/dokuwiki_hiddenheader
 donationurl:  donationurl: 
 ---- ----
Line 23: Line 22:
  
 I made this as a companion to the [[plugin:include|include plugin]]. Include lets you include a page or a section, but it's missing a feature I consider very useful -- the ability to include an excerpt from a large document which is not annotated with section headers. I made this as a companion to the [[plugin:include|include plugin]]. Include lets you include a page or a section, but it's missing a feature I consider very useful -- the ability to include an excerpt from a large document which is not annotated with section headers.
- 
- 
-===== Installation ===== 
- 
-I haven't bothered to make this plugin downloadable. Just copy and paste the following into /lib/plugins/hiddenheader/action.php. 
- 
-<code php lib/plugins/hiddenheader/action.php> 
-<?php 
-/** 
- * hiddenheader Plugin for DokuWiki / action.php 
- * 
- * @license GPL - http://www.gnu.org/copyleft/gpl.html 
- * @author  Eli Fenton 
- */ 
- 
-if (!defined('DOKU_INC')) {die();} 
-if (!defined('DOKU_PLUGIN')) {define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');} 
-require_once DOKU_PLUGIN . 'action.php'; 
- 
-class action_plugin_hiddenheader extends DokuWiki_Action_Plugin { 
-    function getInfo() {return array('author' => 'Eli Fenton', 'name' => 'Hidden Header Plugin', 'url' => 'http://dokuwiki.org/plugin:hiddenheader');} 
- 
-    function register(Doku_Event_Handler $controller) { 
-        $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'AFTER', $this, 'handlePreprocess'); 
-        $controller->register_hook('RENDERER_CONTENT_POSTPROCESS', 'BEFORE', $this, 'handlePostProcess'); 
-        $controller->register_hook('TPL_TOC_RENDER', 'BEFORE', $this, 'handleToc'); 
-    } 
- 
-    function handlePreprocess(&$event, $param) { 
-        // should accumulate in hash 
-        if ($this->hidden) 
-                return; 
-        preg_match_all('/==+\%hide\s*([^=]+)/', $event->data, $m); 
-        $this->hidden = $m && count($m[1])>0 ? $m[1] : null; 
- 
-        if ($this->hidden) 
-            $event->data = preg_replace('/(==+)\%hide/', '$1', $event->data); 
-    } 
- 
-    function handlePostProcess(&$event, $param) { 
-        if ($this->hidden) 
-                foreach ($this->hidden as $h) { 
-                        $event->data[1] = preg_replace('/<h\d[^>]*>(<a name[^>]*>|)'.trim($h).'(<\/a>|)<\/h\d>/', '$1$2', $event->data[1]); 
-        } 
-    } 
- 
-    function handleToc(&$event, $param) { 
-        if ($this->hidden) { 
-            $map = array(); 
-            foreach ($this->hidden as $h) 
-                $map[trim($h)] = 1; 
-            $newdata = array(); 
-            foreach ($event->data as $d) { 
-                if (!$map[$d['hid']]) 
-                    $newdata[] = $d; 
-            } 
-            // I don't know what's special about the number "2." There must be two hidden elements or something. 
-            $event->data = count($newdata)<=2 ? array() : $newdata; 
-        } 
-    } 
- 
-    var $hidden; 
-} 
-</code> 
  
  
Line 126: Line 61:
  
 ==Change Log== ==Change Log==
 +  * 2018-12-31: Fixed some long-standing bugs.
   * 2013-05-22: Updated for Weatherwax. The new DokuWiki doesn't add anchors to headers unless there's a TOC.   * 2013-05-22: Updated for Weatherwax. The new DokuWiki doesn't add anchors to headers unless there's a TOC.
   * 2012-03-29: I just ran into a case where the preprocess command could be called twice by dokuwiki. This might be a bug in Angua. The new code works around this problem.   * 2012-03-29: I just ran into a case where the preprocess command could be called twice by dokuwiki. This might be a bug in Angua. The new code works around this problem.
Line 132: Line 68:
  
 ===== Discussion ===== ===== Discussion =====
 +
 +Thanks, but I have a little problem (Mar2017, Frusterick).  When I link to a hidden section from another page, the hidden headers are shown on the page when I arrive.  The only way to hide them again appears to be to edit the page, make an actual change, and save.
plugin/hiddenheader.txt · Last modified: 2024-02-11 03:40 by zioth

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