Tags:
search1Add my vote for this tag create new tag
, view all tags

FilterPlugin

Substitute and extract information from content by using regular expressions

Description

This plugin allows to substitute and extract information from content by using regular expressions. There are three different types of new functions:

  1. FORMATLIST: maniplulate a list of items; it is highly configurable to define what constitutes a list and how to extract items from it
  2. SUBST, STARTSUBST/STOPSUBST: substiture a pattern in a chunk of text
  3. EXTRACT, STARTEXTRACT/STOPEXTRACT: extract a pattern from a text

While the START-STOP versions of SUBST and EXTRACT work on inline text, the normal versions process a source topic before including it into the current one.

Syntax Rules

SUBST

Syntax: %SUBST{topic="..." ...}%

Insert a topic by processing its content.

  • topic="...": name of the topic text to be processed
  • text="...": text to be processed (has got higher precedence than 'topic')
  • pattern="...": pattern to be extracted or substituted
  • format="...": format expression or pattern substitute
  • header="...": header string prepended to output
  • footer="...": footer string appended to output
  • limit="<n>" maximum number of occurences to extract or substitute counted from the start of the text (defaults to 100000 aka all hits)
  • skip="<n>" skip the first n occurences
  • exclude="...": skip occurences that match this regular expression
  • sort="on,off,alpha,num" order of the formatted items (default "off")
  • expand="on,off": toggle expansion of TWiki markup before filtering (defaults to on)

STARTSUBST, STOPSUBST

Syntax:

%STARTSUBST{...}% 
... 
%STOPSUBST%

Substitute text given inline. see SUBST.

EXTRACT

Syntax: %EXTRACT{topic="..."  ...}%

Extract text from a topic. see SUBST.

STARTEXTRACT, STOPEXTRACT

Syntax:

%STARTEXTRACT{...}% 
... 
%STOPEXTRACT%

Extract content given inline. see SUBST.

FORMATLIST

Syntax: %FORMATLIST{"<list>" ...}%

Formats a list of items. The <list> argument is separated into items by using a split expression; each item is matched against a pattern and then formatted using a format string while being separated by a separator string; the result is prefixed with a header and appended with a footer in case the list is not empty.

  • <list>: the list
  • split="...": the split expression (default ",")
  • pattern="...": pattern applied to each item (default "\s(.*)\s")
  • format="...": the format string for each item (default "$1")
  • header="...": header string
  • footer="...": footer string
  • separator="...": string to be inserted between list items
  • limit="...": max number of items to be taken out of the list (default "-1")
  • skip="...": number of list items to skip, not adding them to the result
  • sort="on,off,alpha,num" order of the formatted items (default "off")
  • reverse="on,off": reverse the sortion of the list
  • unique="on,off": remove dupplicates from the list
  • exclude="...": remove list items that match this regular expression

The pattern string shall group matching substrings in the list item to which you can refer to by using $1, $2, ... in the format string. Any format string (format, header, footer) may contain variables $percnt$, $nop, $dollar and $n. The variable $index referse to the position number within the list being formatted; using $count in the footer or header argument refers to the total number of list elements.

MAKEINDEX

Syntax: %MAKEINDEX{"<list>" ...}%

Formats a list into a multi-column index like in MediaWiki's category topcis. MAKEINDEX insert capitals as headlines to groups of sorted items. It will try to balance all columns equally, and keep track of breaks to prevent "schusterkinder", that is avoid isolated headlines at the bottom of a column.

Parameters:

  • <list>: the list of items
  • split="...": the split expression to separate the <list> into items (default ",")
  • pattern="...": pattern applied to each item (default "(.*)")
  • cols="...": maximum number of cols to split the list into
  • format="...": format of each list item (default "$item")
  • sort="on/off": sort the list (default "on")
  • unique="on/off": removed duplicates (default "off")
  • exclude="...": pattern to check against items in the list to be excluded
  • reverse="on/off": reverse the list (default "off")
  • header="...": format string to prepend to the result
  • footer="..." format string to be appended to the result

Like in FORMATLIST the format parameter can make use of $1, $2, ... variables to match the groupings defined in the pattern argument (like in pattern="(.*);(.*);(.*)") . The first matched grouping $1 will be used as the $item to sort the list.

Examples

Secure Html

%STARTSUBST{pattern="<(a href=\"javascript:.*?)>(.*?)" format="<$1>$2</a>"}% Pop me up %STOPSUBST%

Format Comments

Date Author Headline
%EXTRACT{topic="FilterPlugin" expand="off" pattern=".div class=\"text\">.*?[\r\n]+(.*?)[\r\n]+(?:.*?[\r\n]+)+?-- (.*?) on (.*?)[\r\n]+" format="| $3 | $2 | $1 ... |$n"}%

This is a first comment.
-- TWiki:Main.MichaelDaum on 22 Aug 2005

This is a second comment.
-- TWiki:Main.MichaelDaum on 22 Aug 2005

Extract table data

Pos Description Hours
1 onsite troubleshooting 3
2 normalizing data to new format 10
3 testing server performace 5

%EXTRACT{topic="FilterPlugin" expand="off" pattern="\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|" format=" * it took $3 hours $2$n" skip="1" }%

MAKEINDEX example

Compare with Philosophy articles needing attention

%MAKEINDEX{ "Absolute (philosophy), Accident (philosophy), Actualism, Talk:Adam Weishaupt, Alphabet of human thought, Alterity, Analytic philosophy, Analytic-synthetic distinction, Apologism, Bundle theory, Categories (Stoic), Causal chain, Causality, Coherentism, Conscience, Context principle, Contextualism, Cosmology, De dicto and de re, Dialectical monism, Difference (philosophy), Direct reference theory, Discourse ethics, Dualism, Emergentism, Essence, Ethical naturalism, Exemplification, Existentialism, Fatalism, French materialism, Futilitarianism, Hermeneutics, Hypokeimenon, Identity and change, Idolon tribus, Immanent evaluation, Indeterminacy (Philosophy), Individual, Inherence, Kennisbank Filosofie Nederland, Lazy Reason, Mike Lesser, Libertarianism (metaphysics), Logicism, Mad pain and Martian pain, Materialism, Meaning of life, Metakosmia, Metaphysical naturalism, Milesian school, Mind, Monism, Moral imperative, Multiplicity (philosophy), Mystical philosophy of antiquity, Nature (philosophy), Neomodernism, New England Transcendentalists, Nominalism, Non-archimedean time, Non-rigid designator, Object (philosophy), Ontic, Ontological reductionism, Phenomenology, Philosophical realism, Philosophical skepticism, Philosophy, Pluralism (philosophy), Post-structuralism, Postmodern philosophy, Preferentialism Present (time), Problem of universals, Process philosophy, Rational Animal, Rationalist movement, Relativism, Self (philosophy), Solipsism, Species (metaphysics), Specters of Marx, Substance theory, Talk:The Art of Being Right, Truth-value link, Universal (metaphysics), Utilitarianism, Value judgment, World riddle" cols="3" format="$item" }%

Plugin Installation Instructions

  • Download the ZIP file from twiki.org (see below)
  • Unzip it in your twiki installation directory. Content:
    File: Description:
    data/TWiki/FilterPlugin.txt  
    lib/TWiki/Plugins/FilterPlugin/Core.pm  
    lib/TWiki/Plugins/FilterPlugin.pm  

  • Visit configure in your TWiki installation, and enable the plugin in the {Plugins} section.

Plugin Info

Plugin Author: TWiki:Main.MichaelDaum
Copyright: © 2005-2008, Michael Daum http://michaeldaumconsulting.com
© 2005-2010, TWiki:TWiki/TWikiContributor
License: GPL (GNU General Public License)
Plugin Version: 2010-07-25
Change History:  
2010-07-25: TWikibug:Item6530 - doc improvements
2010-04-29: TWikibug:Item6433 - doc improvements
03 Jul 2008: sorting a list before, not after, formatting it in FORMATLIST
08 May 2008: added 'text' parameter to SUBST and EXTRACT; fixed SUBST as it was pretty useless before
07 Dec 2007: added MAKEINDEX, added lazy compilation
14 Sep 2007: added sorting for EXTRACT and SUBST
02 May 2007: using registerTagHandler() as far as possible; enhanced parameters to EXCTRACT and SUBST
05 Feb 2007: fixed escapes in format strings; added better default value for max number of hits to prevent deep recursions on bad regexpressions
22 Jan 2007: fixed SUBST, added skip parameter to FORMATLIST
18 Dec 2006: using registerTagHandler for FORMATLIST
13 Oct 2006: fixed limit parameter in FORMATLIST
31 Aug 2006: added NO_PREFS_IN_TOPIC
15 Aug 2006: added use strict; and fixed revealed errors
14 Feb 2006: moved in FORMATLIST from the TWiki:Plugins/NatSkinPlugin; added escape variables to format strings
06 Dec 2005: fixed SUBST not to cut off the rest of the text
09 Nov 2005: fixed deep recursion using expand="on"
22 Aug 2005: Initial version; added expand toggle
TWiki Dependency: $TWiki::Plugins::VERSION 1.024
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.005
TWiki:Plugins/Benchmark: GoodStyle nn%, FormattedSearch nn%, FilterPlugin nn%
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/FilterPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/FilterPluginDev
Appraisal: http://TWiki.org/cgi-bin/view/Plugins/FilterPluginAppraisal

Related Topics: TWikiPlugins, DeveloperDocumentationCategory, AdminDocumentationCategory, TWikiPreferences

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatmd5 FilterPlugin.md5 r17 r16 r15 r14 r13 manage 0.2 K 2010-07-26 - 03:26 PeterThoeny  
Compressed Zip archivetgz FilterPlugin.tgz r17 r16 r15 r14 r13 manage 9.9 K 2010-07-26 - 03:25 PeterThoeny  
Compressed Zip archivezip FilterPlugin.zip r22 r21 r20 r19 r18 manage 12.5 K 2010-07-26 - 03:25 PeterThoeny  
Unknown file formatEXT FilterPlugin_installer r8 r7 r6 r5 r4 manage 3.4 K 2010-07-26 - 03:25 PeterThoeny  
Edit | Attach | Watch | Print version | History: r36 < r35 < r34 < r33 < r32 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r36 - 2013-10-16 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.