List Info

Thread: writing a syntax plugin




writing a syntax plugin
country flaguser name
Lithuania
2007-06-18 17:39:13
Hi,
I am trying to grasp development of dokuwiki plugins and
have a few
questions:

if I wanted to write a container plugin with a more complex
syntax:
<blockA>
<A>aaa</A>
<B>bbb</B>
</blockA>
is it better to add a single special pattern
<blockA>.+?</blockA> or
have entry, exit and internal patterns?

Is there perhaps an example of such a plugin - I spent half
an hour
searching but couldn't find anything.

And, continuing the topic of complex syntaxes, can a plugin
store
information, collected during multiple handle(...) calls,
when rendering
a single page? Like collect all the items in <blockA>,
process them
(e.g. sort) and only then render.

Thanks in advance,
Domas

-- 
DokuWiki mailing list - more info at
http://wi
ki.splitbrain.org/wiki:mailinglist

Re: writing a syntax plugin
country flaguser name
United Kingdom
2007-06-18 21:01:40
domas wrote:
> Hi,
> I am trying to grasp development of dokuwiki plugins
and have a few
> questions:
>
> if I wanted to write a container plugin with a more
complex syntax:
> <blockA>
> <A>aaa</A>
> <B>bbb</B>
> </blockA>
> is it better to add a single special pattern
<blockA>.+?</blockA> or
> have entry, exit and internal patterns?
>   

That depends on whether you wish to allow other syntax modes
within your 
own syntax.  If you do, then it is better to use entry, exit
and 
internal patterns.  The only other alternative is to
instantiate a 
second parser to process the data you aren't interested in.
Doing so 
would be resource expensive and may be difficult to handle,
especially 
when you take into account the protected modes.

> Is there perhaps an example of such a plugin - I spent
half an hour
> searching but couldn't find anything.
>   

Try the list plugins.

> And, continuing the topic of complex syntaxes, can a
plugin store
> information, collected during multiple handle(...)
calls, when rendering
> a single page? Like collect all the items in
<blockA>, process them
> (e.g. sort) and only then render.
>   

Theoretically.  If you look in the handler
(inc/parser/handler.php) 
you'll find a nested syntax class.  iirc footnotes makes use
of it.  A 
plugin should be able to make use of the same system. 
Implementation 
may be a little more tricky as its not as straightforward
for a plugin 
to write its own instructions AND to avoid DW having writing
plugin 
instructions.

Aside - I've always felt the plugin handler() method should
be able to 
return a value that tells its caller not to write an
instruction.  It 
may even be relatively painless to add that functionality
without 
disrupting existing plugin behaviour.


> Thanks in advance,
> Domas
>
>   


-- 
DokuWiki mailing list - more info at
http://wi
ki.splitbrain.org/wiki:mailinglist

Re: writing a syntax plugin
country flaguser name
Lithuania
2007-06-19 02:37:54
> > And, continuing the topic of complex syntaxes, can
a plugin store
> > information, collected during multiple handle(...)
calls, when rendering
> > a single page? Like collect all the items in
<blockA>, process them
> > (e.g. sort) and only then render.
> >   
> 
> Theoretically.  If you look in the handler
(inc/parser/handler.php) 
> you'll find a nested syntax class.  iirc footnotes
makes use of it.  A 
> plugin should be able to make use of the same system. 
Implementation 
> may be a little more tricky as its not as
straightforward for a plugin 
> to write its own instructions AND to avoid DW having
writing plugin 
> instructions.
Just wanted to clarify one thing - the plugin object is
instantiated
when parsing a wiki page and destroyed only when the page
has been
rendered? would it be possible then to store collected
information in
class properties? Or is this a wrong approach? The
documentation is a
bit unclear about this.

Thanks,
Domas

-- 
DokuWiki mailing list - more info at
http://wi
ki.splitbrain.org/wiki:mailinglist

Re: writing a syntax plugin
country flaguser name
United Kingdom
2007-06-19 03:46:10
domas wrote:
>>> And, continuing the topic of complex syntaxes,
can a plugin store
>>> information, collected during multiple
handle(...) calls, when rendering
>>> a single page? Like collect all the items in
<blockA>, process them
>>> (e.g. sort) and only then render.
>>>   
>>>       
>> Theoretically.  If you look in the handler
(inc/parser/handler.php) 
>> you'll find a nested syntax class.  iirc footnotes
makes use of it.  A 
>> plugin should be able to make use of the same
system.  Implementation 
>> may be a little more tricky as its not as
straightforward for a plugin 
>> to write its own instructions AND to avoid DW
having writing plugin 
>> instructions.
>>     
> Just wanted to clarify one thing - the plugin object is
instantiated
> when parsing a wiki page and destroyed only when the
page has been
> rendered? would it be possible then to store collected
information in
> class properties? Or is this a wrong approach? The
documentation is a
> bit unclear about this.
>
> Thanks,
> Domas
>
>   

Its the wrong approach.  The handler is called extremely
rarely.  Read 
the sections on caching in both the syntax plugin
documentation and the 
caching documentation itself. Strictly the nested class
isn't a syntax 
mode but a call rewriter, the parser documentation page
should explain 
more about that.


-- 
DokuWiki mailing list - more info at
http://wi
ki.splitbrain.org/wiki:mailinglist

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )