Just a reminder for myself for a generic string replacement plugin ...
Rationale: put formatting rules in an editable topic (let call it
WebPatterns? and
TWikiPatterns? )
Implementation:
- at plugin initialization:
- collect all patterns from the topics (first TWikiPatterns? , then WebPatterns? )
- avoid overriding patterns ( a' la FINALPREFERENCES )
- compile them as pattern variables
- if needed, for the efficiency-concerned, compile at runtime a subroutine that does all replacements
- Instantiate a Safe container (see the Safe CPAN module) enabling some TWiki functions and vars:
- &internalLink(), %handleIncludeFile() ...
- $web, $topic, $username ...
- in the outsidePreHandler apply (eval) the replacements inside the Safe container
Desirable side effects:
- if the pattern specification is verbose enough we obtain automagically its documentation
Examples:
- Double underscore -> bold italic
- Pattern BoldItalicPattern? = /(\s|^)__(.*)__([\s\.\,\?\!]|$)/$1$2$3/go
- Old syntax of INCLUDE tag:
- Pattern OldIncludePattern? = /%INCLUDE:"([^%\"]*?)"%/&handleIncludeFile( $1, $topic, $web, $user )/geo
- Set FINALPATTERNS = BoldItalicPattern? , OldIncludePattern?
PS: I have used
WikiNames? for patterns so that we can document their syntax and examples
--
AndreaSterbini - 20 Feb 2001
I'm almost done with a dumb version of the above idea, you can just define patterns with the syntax
- Replace <pattern> with <replacement>
Where:
- the pattern is a normal regexp
- the replacement is just a string where the symbols $1 .. $9 are replaced with the corresponding matching parts in the pattern.
--
AndreaSterbini - 21 Mar 2001
Topic revision: r4 - 20 Apr 2003 - 05:46:50 -
PeterThoenyPlugins.GenericReplacerPlugin moved from Codev.GenericReplacerPlugin on 18 Sep 2001 - 23:22 by MikeMannix -
put it back