PatternMatcherPlugin
This is a design document for a plugin yet to be written.
The pattern matcher plugin does three things:
- Perform search-and-replace within some subsection of a topic.
- Perform search-extract-replace within some subsection of a topic, i.e. the original patterns remain where they are and the modifed copies are collected and printed in one spot.
- Collect all occurrences of a pattern and pass them via http to a script for processing; insert the output of the script in the rendered text.
Syntax Rules
- %REWRITE{searchfor="pattern" replaceby="pattern" from="fpattern" to="tpattern"}% Works on the section of the topic from the first occurrence of
from
to the last occurrence of to
, which are Perl regular expressions. In that section, applies something like s///
(the Perl search-and-replace operator) to the topic text. searchfor
and replaceby
are required; from
defaults to "^", to
defaults to "$".
- %GREPREWRITE{searchfor="pattern" replaceby="pattern" from="fpattern" to="tpattern"}% As before, but the replacements are not made in the text, but rather all
searcgfir
matches are extraced, replacements done, and the results inserted in place of the GREPREWRITE call.
- %CALLALL{searchfor="pattern" from="fpattern" to="tpattern" url="url" argname="name"}% As before, but instead of doing the replacement, the matches are passed to a script and the output is included in place of the CALLALL. The script i
- %CALLEACH{searchfor="pattern" replaceby="pattern" from="fpattern" to="tpattern"}%
- %CALLALL{}%
Examples
See the perlre manual page for further possiblities. Perl regular expressions are incredibly powerful!
Plugin Settings
Plugin settings are stored as preferences variables. To reference a plugin setting write
%<plugin>_<setting>%
, i.e.
%INTERWIKIPLUGIN_SHORTDESCRIPTION%
- One line description, is shown in the TextFormattingRules topic:
- Set SHORTDESCRIPTION = one line description here
- Debug plugin: (See output in
data/debug.txt
)
Plugin Installation Instructions
Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running.
- Download the ZIP file from the Plugin web (see below)
- Unzip
PatternMatcherPlugin.zip
in your twiki installation directory. Content: File: | Description: |
data/TWiki/PatternMatcherPlugin.txt | Plugin topic |
data/TWiki/PatternMatcherPlugin.txt,v | Plugin topic repository |
lib/TWiki/Plugins/PatternMatcherPlugin.pm | Plugin Perl module |
- Test if the installation was successful:
Plugin Info
Related Topics: DefaultPreferences, System.Plugins,
TWiki:Plugins/PhantomPlugin
--
TWiki:Main/LutzPrechelt - 29 Jun 2004