# # TWiki WikiClone ($wikiversion has version info) # # Copyright (C) 2000-2001 Andrea Sterbini, a.sterbini@flashnet.it # Copyright (C) 2001 Peter Thoeny, Peter@Thoeny.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details, published at # http://www.gnu.org/copyleft/gpl.html # # ========================= # # # Each plugin is a package that contains the subs: # # initPlugin ( $topic, $web, $user, $installWeb ) # commonTagsHandler ( $text, $topic, $web ) # startRenderingHandler( $text, $web ) # outsidePREHandler ( $text ) # insidePREHandler ( $text ) # endRenderingHandler ( $text ) # # initPlugin is required, all other are optional. # For increased performance, all handlers except initPlugin are # disabled. To enable a handler remove the leading DISABLE_ from # the function name. # # ========================= package TWiki::Plugins::SpacedWikiWordPlugin; # ========================= use vars qw( $web $topic $user $installWeb $VERSION $debug $doSpace ); $VERSION = '1.000'; $doSpace = 0; # default is not to space wiki words # ========================= sub initPlugin { ( $topic, $web, $user, $installWeb ) = @_; # check for Plugins.pm versions if( $TWiki::Plugins::VERSION < 1 ) { &TWiki::Func::writeWarning( "Version mismatch between SpacedWikiWordPlugin and Plugins.pm" ); return 0; } # Get plugin debug flag $debug = &TWiki::Func::getPreferencesFlag( "SPACEDWIKIWORDPLUGIN_DEBUG" ); # Is this a skin to space? # TBD: is there a way for a plugin to access regular option parsing??? if ( $ENV{'QUERY_STRING'} =~ /\bskin=(\w+)/ ) # skin there in the first place? { my $skin = $1; my $list = &TWiki::Func::getPreferencesValue( "SPACEDWIKIWORDPLUGIN_SPACESKIN" ); $doSpace = 1 if $list =~ /\b$skin\b/; } # Get param to turn spacing on/off # TBD: is there a way for a plugin to access regular option parsing??? $ENV{'QUERY_STRING'} =~ /\bspace=on\b/ and $doSpace = 1 or $ENV{'QUERY_STRING'} =~ /\bspace=off\b/ and $doSpace = 0; # Get list of special words not to space if ( $doSpace ) { for $word ( split '[ ,:;]+', &TWiki::Func::getPreferencesValue( "SPACEDWIKIWORDPLUGIN_DONTSPACE" )) { $dontspace{$word} = 1; } } # Plugin correctly initialized &TWiki::Func::writeDebug( "- TWiki::Plugins::SpacedWikiWord::initPlugin( $web.$topic ) does space: $doSpace" ) if $debug; return 1; } # ========================= sub commonTagsHandler { $_[0] =~ s/%TOPICSPACED%/&spacedWikiWord($_[1])/geo; } sub spacedWikiWord # $_[0] is the word to space { return $_[0] if $dontspace{$_[0]}; $_[0] =~ s/([a-z0-9])([A-Z])/$1 $2/g; #lower alphanum followed by upper $_[0] =~ s/([a-zA-Z])([0-9])/$1 $2/g; #letter followed by number $_[0] =~ s/([A-Z]+)([A-Z][a-z0-9])(?!$)/$1 $2/g; #ACRONYM followed by Word $_[0] =~ s/([A-Z]+)([A-Z][a-rt-z0-9]$)/$1 $2/; #but not plural s at EOL return $_[0]; } 1;