Table of Contents

CommentSrc

Last update: 2006-08-23

This is an existing plugin that I modified to better suit my tastes.

Example

### Comments begin with three or more # characters

Source code

The original source did not specify a copyright. This plugin is hereby placed in the public domain.

syntax.php
<?php
 
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');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_commentsrc extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Tom N Harris',
            'email'  => 'tnharris [at] whoopdedo.org',
            'date'   => 'Wed, Aug 23, 2006',
            'name'   => 'commentsrc Plugin',
			'desc'   => 'Make text only visible when editing a page.
                         ### Three or more # at the beginning of a line.
                         Based on original plugin by iDo [[doku>plugin:commentsrc]]',
            'url'    => 'http://whoopdedo.org/doku/wiki/commentsrc',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 49;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addEntryPattern('~~COMMENT:\[',$mode,'plugin_commentblock');
      $this->Lexer->addSpecialPattern('\n#{3,}[^\n]*?(?=\n)',$mode,'plugin_commentsrc');
    }
 
    function postConnect() {
      //$this->Lexer->addPattern('\n#{2,}','plugin_commentsrc');
      //$this->Lexer->addExitPattern('\n','plugin_commentsrc');
      $this->Lexer->addExitPattern('\]~~','plugin_commentblock');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
		return true;
    }  
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        return true;
    }
 
}
 
//Setup VIM: ex: et ts=4 :