HashHeadings – Simple Headings for Dokuwiki

Table of Contents

HashHeadings – Simple Headings for Dokuwiki

Write Dokuwiki headings with hash character “#”. For example: ##heading2.

HashHeadings syntax was inspired by MarkDown.

HashHeadings is a Dokuwiki syntax plugin, tested with Dokuwiki 2007-06-26b.tgz (local mirror).


Easier to type

HashHeadings makes it faster and easier to type wiki syntax. Let’s compare!

HashHeadings syntax:

# Level 1 Headline
## Level 2 Headline

Original Dokuwiki syntax:

====== Level 1 Headline ======
===== Level 2 Headline =====

I think it’s easy to count to one or two. However, original Dokuwiki syntax makes you count (7-1) or (7-2) twice.


Source Code of HashHeadings

<?php /**
 *
 *  @author     Tero Karvinen http://www.iki.fi/karvinen
 *  @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 *  @version    0.1
**/
 
// This plugin must be placed in: lib/plugins/hashhead/syntax.php
 
//  Hashead is based on htag syntax plugin by Adam B. Ross abr.programmer at gmail.com, GPLv2
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_hashhead extends DokuWiki_Syntax_Plugin {
        function getInfo() {
                return array (
                        'author' => 'Tero Karvinen',
                        'email' => 'karvinen at iki.fi',
                        'date' => '2007-11-24',
                        'name' => 'HashHead',
                        'desc' => 'Headings with hash "#", like in MarkDown. Eg. "# heading1", "## heading2"',
                        'url' => 'http://www.iki.fi/karvinen/hashhead'
                );
        }
 
        // header specific
        function getType() { return 'baseonly'; }
        // headings shouldn't be parsed..
        function accepts($mode) { return false; }
        function connectTo( $mode ) {
                $this->Lexer->addSpecialPattern( '^#+[^n]+n', $mode, 'plugin_hashhead' );
                # notice the looking for non-linefeed "[^n]" instead of any character "."
                # otherwise this regexp will replace the rest of the page
        }
        // Doku_Parser_Mode 60
        // header (numbered headers) 45
        function getSort() { return 44; }
        function handle( $match, $state, $pos, &$handler )
        {
                global $conf;
                preg_match('/^(#+)([^n]+)n/', $match, $hits);
                #print_r($hits);
                # illogically, $match is the input string; $hits is array of what preg_match found. 
				$title = $hits[2];
				$title = trim($title);
				$level = strlen($hits[1]);	# "###"	-> 3
                if( $handler->status['section'] ) $handler->_addCall('section_close',array(), $pos);
                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;
                }
                $handler->_addCall('header',array($title,$level,$pos), $pos);
                $handler->_addCall('section_open',array($level),$pos);
                $handler->status['section'] = true;
                return true;
        }
        function render( $format, &$renderer, $data )
        {
                return true;
        }
}
?>



Posted in Old Site | Tagged , , , , , , , , | Comments Off on HashHeadings – Simple Headings for Dokuwiki

Comments are closed.