* level 1 ** level 2 *** level 3 #### # level 1 ## level 2 ### level 3 #3 restart numbering from 3 #### [col1][col2][col3] [col1][col2][col3] #### use strict; my $text=qq| -This is a h1 title ''This is italized'' and here, ''''this is bold'''' on this line ''''''this is bold italic'''''' on this line ---- *list1 **list2 ***list3 #unordered list1 ##unordered list2 ###unordered list3 [''''name''''][''color''][''''''age''''''] [bob][red][32] [fred][orange][55] |; my $html=wiki2html($text); print $html; exit; ############# sub wiki2html{ my $str=shift || return; #http://wiki.beyondunreal.com/wiki/Wiki_Markup #----
#At the beginning, -

, --

, ---

#Unorderd lists *, ** #Ordered lists #, ## #tables [col1][col2] #''sdfs'' , ''''sdfs'''' , ''''''sddfs'''''' my @lines=split(/[\r\n]/,$str); my $linecnt=@lines; my $dot='&#' . '9679' . ';'; my $space='&' . 'nbsp' . ';'; my %Marker=( ul => 0, ol => 0, table => 0, ); for(my $x=0;$x<$linecnt;$x++){ $lines[$x]=strip($lines[$x]); my $original=$lines[$x]; my $break=1; #----
$lines[$x]=~s/\-{4,4}/\
/sig; #At the beginning, -

, --

, ---

if($lines[$x]=~/^(\-{1,3})(.+)/s){ my $dashes=$1; my $txt=$2; my $count = $dashes =~ tr/\-//; $lines[$x]=qq|$txt|; $break=0; } #Unorderd lists *, ** if($lines[$x]=~/^([\*\.\0]+)(.+)/s){ my $stars=$1; my $txt=$2; my $count = $stars =~ tr/[\*\.\0]//; #$txt .= qq||; if($count > $Marker{ul}){ $lines[$x]="
  • " . $txt; $Marker{ul}=$count; } elsif($count == $Marker{ul}){ $lines[$x]="
  • " . $txt; } else{ $lines[$x] = "
"; if(length($txt)){$lines[$x] .= "
  • " . $txt ;} $Marker{ul}=$count; } $break=0; } elsif($Marker{ul}){ for(my $u=0;$u<$Marker{ul};$u++){ $lines[$x] = "" . $lines[$x]; } $Marker{ul}=0; } #Orderd lists #, ## if($lines[$x]=~/^([\#]+)(.+)/s){ my $stars=$1; my $txt=$2; my $count = $stars =~ tr/[\#]//; #$txt .= qq||; if($count > $Marker{ol}){ $lines[$x]="
    1. " . $txt; $Marker{ol}=$count; } elsif($count == $Marker{ol}){ $lines[$x]="
    2. " . $txt; } else{ $lines[$x] = "
    "; if(length($txt)){$lines[$x] .= "
  • " . $txt ;} $Marker{ol}=$count; } $break=0; } elsif($Marker{ol}){ for(my $u=0;$u<$Marker{ol};$u++){ $lines[$x] = "" . $lines[$x]; } $Marker{ol}=0; } if(length($lines[$x])==0){$break=0;} #''sdfs'' , ''''sdfs'''' , ''''''sddfs'''''' $lines[$x]=~s/\'{6,6}(.+?)\'{6,6}/\1<\/i><\/b>/sig; $lines[$x]=~s/\'{4,4}(.+?)\'{4,4}/\1<\/b>/sig; $lines[$x]=~s/\'{2,2}(.+?)\'{2,2}/\1<\/i>/sig; #links [[ ]] if($lines[$x]=~/\[\[(.+?)\]\]/s){ $lines[$x]=~s/\[\[(.+?)\]\]/\\1<\/a>/sg; } #tables [col1][col2] my @cols=(); while($lines[$x]=~/\[(.+?)\]/sg){ push(@cols,$1); } my $colcnt=@cols; if($colcnt){ $break=0; $lines[$x]=''; if(!$Marker{table}){ $lines[$x] .= qq|\n|; $Marker{table}=1; } $lines[$x] .= ""; foreach my $col (@cols){$lines[$x] .= qq||;} $lines[$x] .= ""; } elsif($Marker{table}){ $lines[$x] = "
    $col
    "; $Marker{table}=0; } #$lines[$x]=qq|\n| . $lines[$x]; if($break){$lines[$x] .= "
    ";} } if($Marker{ul}){ for(my $u=0;$u<$Marker{ul};$u++){ push(@lines,""); } $Marker{ul}=0; } if($Marker{ol}){ for(my $u=0;$u<$Marker{ol};$u++){ push(@lines,""); } $Marker{ol}=0; } if($Marker{table}){ push(@lines,""); $Marker{table}=0; } return join("\r\n",@lines); } ############### sub strip{ #usage: $str=strip($str); #info: strips off beginning and endings returns, newlines, tabs, and spaces my $str=shift; if(length($str)==0){return;} $str=~s/^[\r\n\s\t]+//s; $str=~s/[\r\n\s\t]+$//s; return $str; }