DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:htag

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:htag [2007-08-03 02:23] spadeplugin:htag [2022-01-12 01:18] (current) – Obsolete Klap-in
Line 1: Line 1:
 +====== H-Tag Plugin ======
  
 +---- plugin ----
 +description: An alternative heading syntax
 +author     : Adam B. Ross
 +email      : abr.programmer@gmail.com
 +type       : syntax
 +lastupdate : 2007-07-23
 +compatible : 2013-05-10 2012-10-13 2012-01-25 and 2011-05-25
 +depends    : 
 +conflicts  : numberedheadings
 +similar    : 
 +tags       : editing, headings,!obsolete #as not maintained, no download available 
 +----
 +
 +^  Author | [[abr.programmer@gmail.com|Adam B. Ross]] |
 +^  Version | 0.95 (2007-07-23) |
 +^  DokuWiki version | Tested on v.2007-06-26|
 +
 +===== Description =====
 +This is similar to Tony Pujal's @h# hack found in the discussion of the [[tips:reverseheadertags|inverse headings hack]].  It adds an easy-to-read syntax for headings in addition to the wiki's, and as a plugin.  This is my first effort at playing with DokuWiki code, so please point out any mistakes.
 +===== Usage =====
 +  h1. A Heading to Rule Them All!
 +
 +This plugin will convert ''h1.'' through ''h6.'' to the equivalent headings.  It is not case sensitive, but does need to be marked at the start of the line.
 +
 +This syntax breaks compatibility with any code or plugins that manipulate the use of ''='''s to mark headings, such as [[plugin:numberedheadings]].
 +
 +A demo and plugin download will be made available once I finish deploying my wiki ;P FIXME (URL to author's wiki ?)
 +
 +===== Installation =====
 +  - Create the directory ''dokuwiki/lib/plugins/htag''.
 +  - Copy the code below to ''syntax.php''.
 +
 +
 +
 +==== Source Code ====
 +<code php syntax.php>
 +<?php /**
 +  This plugin provides alternative heading syntax.
 +  It converts h1. to h6. to the DokuWiki headings
 + *
 +  @author     Adam B. Ross <abr.programmer@gmail.com>
 +  @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 +  @version    htag syntax plugin, v0.9
 +  @since      23-Jul-2007
 +**/
 +
 +class syntax_plugin_htag extends DokuWiki_Syntax_Plugin {
 +
 +        function getInfo() {
 +                return array ( 
 +                        'author' => 'Adam B. Ross',
 +                        'email' => 'grayside@gmail.com',
 +                        'date' => '2007-07-23',
 +                        'name' => 'Heading Level Tag',
 +                        'desc' => 'Adds outline-style markup (h1.~) syntax for headings.',
 +                        'url' => 'https://www.dokuwiki.org/plugin:htag'
 +                );
 +        }
 +
 +        // header specific
 +        function getType() { return 'baseonly'; }
 +
 +        // headings shouldn't be parsed..
 +        function accepts($mode) { return false; }
 +
 +        function connectTo( $mode ) {
 +                $this->Lexer->addSpecialPattern( '^[hH][1-6]\.[ \t]*[^\n]+(?=\n)', $mode, 'plugin_htag' );
 +        }
 +
 +        // Doku_Parser_Mode 60
 +        // header (numbered headers) 45
 +        function getSort() { return 44; }
 +        
 +        function handle( $match, $state, $pos, Doku_Handler $handler) {
 +        {
 +                global $conf;
 +                preg_match( '/^h\d/i', $match, $htag );
 +                $title = substr( $match, 3 );
 +                $title = trim($title);
 +                $level = substr( $htag[0], 1, 1 );
 +
 +                if( $handler->getStatus('section') ) $handler->addCall('section_close',array(), $pos);
 +                if( $level <= $conf['maxseclevel'] ) {
 +                    $handler->addCall('section_edit',array($handler->getStatus('section_edit_start'), $pos-1,
 +                                $handler->getStatus('section_edit_level'), $handler->getStatus('section_edit_title')), $pos);
 +                    $handler->setStatus('section_edit_start', $pos);
 +                    $handler->setStatus('section_edit_level', $level);
 +                    $handler->setStatus('section_edit_title', $title);
 +                }
 +                $handler->addCall('header',array($title,$level,$pos), $pos);
 +                $handler->addCall('section_open',array($level),$pos);
 +                $handler->setStatus('section', true);
 +
 +                return true;
 +        }
 +
 +        function render( $format, Doku_Renderer $renderer, $data) {
 +        {
 +                return true;
 +        }
 +
 +}
 +</code>
 +
 +===== Changelog =====
 +  * **Version ..** 2022: some code cleanup, not tested
 +  * **Version 0.95 (2007-07-23)**: Fixed no-sections bug.
 +  * **Version 0.9 (2007-07-17)**: First published version.
 +
 +
 +
 +===== Discussion =====
 +==== Spurious blank lines ====
 +If I create a pair of headers:
 +<code>
 +h1. Heading 1
 +h2. Heading 2
 +</code>
 +and then export the page using the odt plugin, then I get spurious blank lines between the headings.
 +
 +Looking at the content.xml file I can see that these are due to %%<text:p text:style-name="Text_20_body"/>%% tags.
 +
 +However, odt exports ok if the regular heading formats are used.
 +
 +Anyone got any ideas what's causing this?
 +
 +==== Error - 10 Feb 2011 ====
 +
 +Causes the error : "Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Doku_Renderer_metadata::section_edit' was given in /var/www/redmine-wiki/inc/parserutils.php on line 419"
 +on the first load for each page.  Refreshing the page will have it come up clean.  Clearing the cache makes no difference.
 +
 +----
 +
 +**11 Dec 2011** (kaj.wiik ə iki.fi)
 +
 +Edit the following lines out (section edit is done now elsewhere):
 +
 +<code>
 +if( $level <= $conf['maxseclevel'] ) {
 +                    $handler->_addCall('section_edit',array($handler->status['section_edit_start'], $pos-1,
 +                                $handler->status['section_edit_level'], $handler->status['section_edit_title']), $pos);
 +                    $handler->status['section_edit_start'] = $pos;
 +                    $handler->status['section_edit_level'] = $level;
 +                    $handler->status['section_edit_title'] = $title;
 +}
 +</code>
 +  

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