[dokuwiki] Re: Sample Syntax Plugin without Effect

  • From: Lars Paulsen <lars_paulsen@xxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Mon, 22 Mar 2021 21:17:04 +0100

Hi David,

the mailing list is not used very much. I think you will receive more answers if you post your problem in the forum.
There is an extra section for Development questions, see https://forum.dokuwiki.org/t/development.

Greetings,
Lars

Am 22.03.21 um 21:02 schrieb David Michaelis (Redacted sender davmic for DMARC):

Hi all,

I wanted to develop a Plugin which, amongst others, provides a new syntax. But 
my first attempt does not seem to work at all. I've tried to adhere to the 
Syntax Plugin from Dokuwiki (devel:syntax_plugins), and reviewed the source 
code of other working plugins, but to no avail.

I can confirm that the PHP file is actually loaded, because when I introduce a 
syntax error, Dokuwiki breaks. But I haven't been able to debug things further, 
because dbglog() outputs nothing in the debug log, and allowdebug is enabled. I 
have tried to put the dbglog call into the render() method of the commentsyntax 
plugin, just to check, but it also has no effect there when I preview a page 
which uses the comment syntax.

The plugin is currently in lib/plugins/testbutton and I have put the two files contained in 
this folder (plugin.info.txt and syntax.php) at the end of the mail, hope that's okay. When I 
write "<testbutton/>" on any page, this string is output verbatim and not 
replaced.

What mistakes can you spot? If it looks okay so far, where else could I check?

Greetings,
David



plugin.info.txt
base   testbutton
author David Michaelis
email  David.Michaelis@xxxxxxxxxxx
date   2020-02-26
name   Test Button
desc   displays a test button
url    https://www.example.org/plugin:testbutton



syntax.php
<?php
if (!defined('DOKU_INC')) die();

class syntax_plugin_testbutton extends DokuWiki_Syntax_Plugin {
     function getType() {
         return 'substitution';
     }

     function getAllowedTypes() {
         return array();
     }

     function getPType() {
         return 'normal';
     }

     function getSort() {
         return 195;
     }

     function connectTo($mode) {
         
$this->Lexer->addSpecialPattern('<testbutton/>',$mode,'plugin_testbutton');
     }

     function handle($match, $state, $pos, Doku_Handler $handler) {
         return array();
     }

     function render($mode, Doku_Renderer $R, $data) {
         if($mode == 'xhtml') {
             $R->doc .= '<button id="testbutton">Click here</button>';
             return true;
         }
         return false;
     }
}
--
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: