#!/usr/bin/perl use strict; use warnings; # $Id: wiki.pm 88 2008-02-05 12:45:40Z ed $ # $URL: svn+ssh://fw/repos/code/perl/pagebuild/wiki.pm $ # # short class to turn pseudo wiki mark up to html. # 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA package wiki; sub new { my $self = {}; bless( $self ); } # set_config should be called with a hash prior to make_html sub set_config { my $self = shift; my $cr = shift; $self->{config} = $cr; my %temp = ( h1start => "", h2start => "", h3start => "", h4start => "", h1end => "", h2end => "", h3end => "", h4end => "", tablestart => "", tableend => "", trstart => "", trend => "", tdstart => "", tdend => "", thstart => "", thend => "" ); foreach( sort keys( %temp ) ) { if( !defined( $self->{config}->{$_} ) ) { die( "Hash value $_ not defined" ); } } } # this function should be called wi the content to process as it's first argument. the processed content is returned to caller sub make_html { my $self = shift; my $content = shift; my %c = %{$self->{config}}; my @lines = split( /\n/, $content ); foreach( @lines ) { $_ =~ s/^====(.*?)====$/${c{'h4start'}}$1${c{'h4end'}}/ig; $_ =~ s/^===(.*?)===$/${c{'h3start'}}$1${c{'h3end'}}/ig; $_ =~ s/^==(.*?)==$/${c{'h2start'}}$1${c{'h2end'}}/ig; $_ =~ s/^=(.*?)=$/${c{'h1start'}}$1${c{'h1end'}}/ig; $_ =~ s/'''(.*?)'''/$1<\/b>/ig; $_ =~ s/''(.*?)''/$1<\/i>/ig; $_ =~ s/^{\|$/${c{'tablestart'}}/ig; $_ =~ s/^\|}$/${c{'tableend'}}/ig; $_ =~ s/\|-/${c{'trstart'}}${c{'tdstart'}}/ig; $_ =~ s/-\|/${c{'tdend'}}${c{'trend'}}/ig; $_ =~ s/\|\|/${c{'tdend'}}${c{'tdstart'}}/ig; $_ =~ s/!-/${c{'trstart'}}${c{'thstart'}}/ig; $_ =~ s/-!/${c{'thend'}}${c{'trend'}}/ig; $_ =~ s/!!/${c{'thend'}}${c{'thstart'}}/ig; } return( join( "\n", @lines ) ); } 1;