[dokuwiki] Re: Syntax plugins: act on links

  • From: Christopher Smith <chris@xxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Mon, 25 Aug 2008 12:27:14 +0100


On 24 Aug 2008, at 14:07, Aurelien Bompard wrote:


Any idea why this does not work ? A possible solution ?


Why it doesn't work?

It'd take too long to explain fully here, to become more familiar with how the parser works take a look at http://www.dokuwiki.org/ devel:parser.

In brief, the parser looks for the earliest match (match commencing on the nearest character to the start of the string). Patterns are ordered by sort order. So, although your pattern is higher in the sort order, it matches later in the string. And, because links are substition [sic], there is no parsing of the link data itself.

Some possible solutions.

(1)
- Record the substitutions in metadata (handle 'meta' format in your syntax). - Preprocess the wiki text to make the substitution, say by handling the PARSER_WIKITEXT_PREPROCESS event

This method will cache the results of the substitution, which may or may not be desirable. It will also process text inside plugin using substition syntax modes (probably desirable) and within protected modes (probably undesirable).

(2)
- Record the substitutions somewhere, choice of location is dependent on the acceptable level of caching. Personally, I'd still go with metadata. - Postprocess the parser output* (RENDERER_CONTENT_POSTPROCESS) or the cached results** (TPL_ACT_RENDER) to make the substitutions.

*Allows substituted output to be cached.

**This method allows the html (with tokens for substitution) to be cached, but would require some form of search/replace on every page view which required substitutions.

Suffers same issues and benefits wrt substition and protected modes.

(3)
- include a pattern in your plugin to handle all the different link types. Perform any substitutions and then hand the results to DW's link processing functions. This would probably have to happen in the handler rather than the renderer. You can avoid carrying out substitutions inside protected modes but will need to define patterns to match any substition modes where it makes sense to use a token - very difficult for plugins.


Note, dokuwiki indexes the wiki text not the rendered output, which could result in unexpected snippets being displayed in the search results.

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

Other related posts: