App-SocialCalc-Multiplayer

 view release on metacpan or  search on metacpan

socialcalc/SocialCalcServersideUtilities.pm  view on Meta::CPAN

#
# Returns $estring with expanded simple wikitext - used for error messages
# 

sub ExpandMarkup {

   my ($estring, $sheet, $options) = @_;

   return $estring;

   }


# # # # # # # # # #
# estring = ExpandWikitext($estring, $sheet, $options, $valueformat)
#
# Returns $estring with expanded wikitext - used for cell data
# 

sub ExpandWikitext {

   my ($estring, $sheet, $options, $valueformat) = @_;

   if (ref $options->{callback_object}) {
       return $options->{callback_object}->expand_wikitext(@_);
   }

   # handle the cases of text-wiki...

   if ($valueformat =~ m/^text-wiki(.+)$/) { # something more than just plain wikitext
      my $subtype = $1;
      my $result = "";

      if ($subtype eq "-pagelink") { # not very secure or robust -- just a demo
         if ($estring =~ m/\[(\S+)\s+(.+)\]$/) {
            my $url = URLEncode("$1");
            my $scestring = SpecialChars($2);
            $result = qq!<a href="?pagename=$url">$scestring</a>!;
            }
         elsif ($estring =~ m/\[(.*)\]$/) {
            my $url = URLEncode("$1");
            my $scestring = SpecialChars($1);
            $result = qq!<a href="?pagename=$url">$scestring</a>!;
            }
         else {
            my $url = URLEncode($estring);
            my $scestring = SpecialChars($estring);
            $result = qq!<a href="?pagename=$url">$scestring</a>!;
            }
         }        
      else {
         $result = SpecialChars("$subtype: $estring");
         }

      return $result || "&nbsp;";

      }

   $estring =~ s!\[(http:.+?)\s+(.+?)\]!'{{lt}}a href={{quot}}' . URLEncode("$1") . "{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!egs; # Wiki-style links
   $estring =~ s!\[link:(.+?)\s+(.+?)\:link]!'{{lt}}a href={{quot}}' . URLEncode("$1") . "{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!egs; # [link:url text:link] to link
   $estring =~ s!\[popup:(.+?)\s+(.+?)\:popup]!'{{lt}}a href={{quot}}' . URLEncode("$1") . "{{quot}} target={{quot}}_blank{{quot}}{{gt}}$2\{{lt}}/a{{gt}}"!egs; # [popup:url text:popup] to link with popup result
   $estring =~ s!\[image:(.+?)\s+(.+?)\:image]!'{{lt}}img src={{quot}}' . URLEncode("$1") . '{{quot}} alt={{quot}}' . SpecialCharsNL("$2") . '{{quot}}{{gt}}'!egs; # [image:url alt-text:image] for images
#   $string =~ s!\[page:(.+?)(\s+(.+?))?]!wiki_page_command($1,$3, $linkstyle)!egs; # [page:pagename text] to link to other pages on this site

   # Convert &, <, >, "

   $estring = SpecialChars($estring);

   # Multi-line text has additional formatting options ignored for single line

   if ($estring =~ m/\n/) {
      my ($str, @closingtag);
      foreach my $line (split /\n/, $estring) { # do things on a line-by-line basis
         $line =~ s/\r//g;
         if ($line =~ m/^([\*|#|;]{1,5})\s{0,1}(.+)$/) { # do list items
            my $lnest = length($1);
            my $lchr = substr($1,-1);
            my $ltype;
            if ($lnest > @closingtag) {
               for (my $i=@closingtag; $i<$lnest; $i++) {
                  if ($lchr eq '*') {
                     $ltype = "ul";
                     }
                  elsif ($lchr eq '#') {
                     $ltype = 'ol';
                     }
                  else {
                     $ltype = 'dl';
                     }
                  $str .= "<$ltype>";
                  push @closingtag, "</$ltype>";
                  }
               }
            elsif ($lnest < @closingtag) {
               for (my $i=@closingtag; $i>$lnest; $i--) {
                  $str .= pop @closingtag;
                  }
               }
            if ($lchr eq ';') {
               my $rest = $2;
               if ($rest =~ m/\s*(.*?):(.*)$/) {
                  $str .= "<dt>$1</dt><dd>$2</dd>";
                  }
               else {
                  $str .= "<dt>$rest</dt>";
                  }
               }
            else {
               $str .= "<li>$2</li>";
               }
            next;
            }
         while (@closingtag) {
            $str .= pop @closingtag;
            }
         if ($line =~ m/^(={1,5})\s(.+)\s\1$/) { # = heading =, with equal number of equals on both sides
            my $neq = length($1);
            $str .= "<h$neq>$2</h$neq>";
            next;
            }
         if ($line =~ m/^(:{1,5})\s{0,1}(.+)$/) { # indent 20pts for each :



( run in 1.461 second using v1.01-cache-2.11-cpan-364913b4093 )