DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:commentsrc

commentsrc Plugin

Compatible with DokuWiki

No compatibility info given!

plugin This plugin provides the ability to put comment only visible when you edit the page

Last updated on
2005-12-14
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to comment, commentsyntax, htmlcomment, wrap

Tagged with annotations, comment, hide

Syntax

Just put your comment between !- and -!:

!-I love dokuwiki-!

Install

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Code

lib/plugins/commentsrc/syntax.php:

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' => 'iDo',
            'email'  => 'iDo@woow-fr.com',
            'date'   => '14/12/2005',
            'name'   => 'commentsrc Plugin',
            'desc'   => 'Make texte only visible when editing a page',
            'url'    => 'https://www.dokuwiki.org/plugin:commentsrc',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 51;
    }
 
    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern("!-.*-!",$mode,'plugin_commentsrc');
    }
 
    /**
     * 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 enc=utf-8 :

Comments

There is already another plugin which does just that: Comment. The only difference is the markup, /* hidden comment */ as in many programming languages. — Esther Brunner 2005-12-14 16:33

Oups sorry, that's right :) i didn't see it :/

I cannot get this to work in DokuWiki-2005-09-22. The complete comment, plus the surrounding tags, is visible on the page. (I cannot get Hidden Comment to work either.) — Chris Lale 2005-12-15 13:53


You say in the instructions to use != and =! for comments when it should be !- and -!


Hi. I propose the fix of A. This patch has the following effects.

  1. plugin_commentsrc can use !- -! besides /* */.
  2. Two or more comments can be used in one page. (The released version was able to use only one comment in one page. )

I like this plugin because the light weight.

--- lib/plugins/commentsrc/syntax.php.orig      2005-12-14 14:40:20.000000000 +0900
+++ lib/plugins/commentsrc/syntax.php   2006-08-01 20:31:45.000000000 +0900
@@ -42,9 +42,18 @@
      * Connect pattern to lexer
      */
     function connectTo($mode) {
-      $this->Lexer->addSpecialPattern("!-.*-!",$mode,'plugin_commentsrc');
+      $this->Lexer->addEntryPattern("!-", $mode, 'plugin_commentsrc');
+      $this->Lexer->addEntryPattern("/\*", $mode, 'plugin_commentsrc');
     }
-
+
+    /**
+     * Release pattern to lexer
+     */
+    function postConnect() {
+      $this->Lexer->addExitPattern("-!", 'plugin_commentsrc');
+      $this->Lexer->addExitPattern("\*/", 'plugin_commentsrc');
+    }
+
     /**
      * Handle the match
      */
@@ -62,4 +71,4 @@
 }
 
 //Setup VIM: ex: et ts=4 enc=utf-8 :
-?>
\ No newline at end of file
+?>

Kohei MATSUSHITA 2006-08-01 20:45 JST


Kohei is right. The .* part in the pattern "!-.*-!" would eat as much as possible, thus eating the text between two comments:

!- comment -! Disappearing text !- comment again -!

Esther's plugin is using .*? which matches “as little as possible”. This is (i think) equivalent to Kohei's solution with entrypattern and exitpattern. — 2


I patched it (by hand) with Kohei MATSUSHITA's notes (didn't get Esther 'comment' plugin working), and I used "[^A-Za-z0-9_-]/\*" instead of “/\*” because I noticed some problems with some texts like: “rm /some/folder/*” where '/*' should not be seen as the start of a piece of hidden text; still got some problems with two lines below eachother having only /* comment */ on them

Sebastiaan Giebels 2010-12-10 18:04


plugin/commentsrc.txt · Last modified: 2023-12-21 16:49 by Aleksandr

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