[Home]WikiPatches/TableSyntaxCommonMarkup

UseModWiki | WikiPatches | RecentChanges | Preferences

Comment from [Egil Kvaleberg]: The full patch is below, but a cut/paste created practical problems for me (esp. with how greater and less than signs turned out), so I would suggest using the patch program instead an apply this:


===================================================================
RCS file: /home/cvs/edge/src/wiki/wiki.pl,v
retrieving revision 1.2
diff -c -r1.2 wiki.pl
*** wiki.pl     24 May 2003 12:32:24 -0000      1.2
--- wiki.pl     24 May 2003 12:51:10 -0000
***************
*** 1236,1241 ****
--- 1236,1244 ----
      if ($UseHeadings) {
        s/(^|\n)\s*(\=+)\s+([^\n]+)\s+\=+/&WikiHeading($1, $2, $3)/geo;
      }
+     ## Tables:
+     s/^\|([^|]*)\s*/<TR class=wikitablerow><TD class=wikitablecell>$1<\/TD>\n/g; # start of line; new table-row ## TAB
+     s/\|([^|]*)\s*/<td class=wikitablecell>$1<\/td>\n/g; #table new field ## TAB
    }
    return $_;
  }
***************
*** 1243,1248 ****
--- 1246,1252 ----
  sub WikiLinesToHtml {
    my ($pageText) = @_;
    my ($pageHtml, @htmlStack, $code, $depth, $oldCode);
+   my ($tag); #table
                                                                                                                                     
    @htmlStack = ();
    $depth = 0;
***************
*** 1264,1274 ****
      } elsif (/^[ \t].*\S/) {
        $code = "PRE";
        $depth = 1;
      } else {
        $depth = 0;
      }
      while (@htmlStack > $depth) {   # Close tags as needed
!       $pageHtml .=  "</" . pop(@htmlStack) . ">\n";
      }
      if ($depth > 0) {
        $depth = $IndentLimit  if ($depth > $IndentLimit);
--- 1268,1285 ----
      } elsif (/^[ \t].*\S/) {
        $code = "PRE";
        $depth = 1;
+     } elsif (/^[\|\+].*\S/) { #table
+       $code = "TABLE"; #table
+       $depth = 1; #table
      } else {
        $depth = 0;
      }
      while (@htmlStack > $depth) {   # Close tags as needed
!       $tag = pop(@htmlStack); #table
!       if ($tag eq "TABLE") { #table
!       $pageHtml .= "</TR>\n"; #table
!       $tag = "table";      } #table
!       $pageHtml .= "</" . $tag . ">\n"; #table
      }
      if ($depth > 0) {
        $depth = $IndentLimit  if ($depth > $IndentLimit);
***************
*** 1281,1287 ****
        }
        while (@htmlStack < $depth) {
          push(@htmlStack, $code);
!         $pageHtml .= "<$code>\n";
        }
      }
      s/^\s*$/<p>\n/;                        # Blank lines become <p> tags
--- 1292,1302 ----
        }
        while (@htmlStack < $depth) {
          push(@htmlStack, $code);
!       if ($code eq "TABLE") { #table
!         $pageHtml .= "<TABLE class=wikitable>\n"; #table ## TAB
!       } else { #table
!         $pageHtml .= "<$code>\n";
!       } #table
        }
      }
      s/^\s*$/<p>\n/;                        # Blank lines become <p> tags

This is the origial:

sub CommonMarkup {
  my ($text, $useImage, $doLines) = @_;
  local $_ = $text;

  if ($doLines < 2) { # 2 = do line-oriented only
    # The <nowiki> tag stores text with no markup (except quoting HTML)
    s/\<nowiki\>((.|\n)*?)\<\/nowiki\>/&StoreRaw($1)/ige;
    # The <pre> tag wraps the stored text with the HTML <pre> tag
    s/\<pre\>((.|\n)*?)\<\/pre\>/&StorePre($1, "pre")/ige;
    s/\<code\>((.|\n)*?)\<\/code\>/&StorePre($1, "code")/ige;
    if ($HtmlTags) {
      my ($t);
      foreach $t (@HtmlPairs) {
        s/\<$t(\s[^<>]+?)?\>(.*?)\<\/$t\>/<$t$1>$2<\/$t>/gis;
      }
      foreach $t (@HtmlSingle) {
        s/\<$t(\s[^<>]+?)?\>/<$t$1>/gi;
      }
    } else {
      # Note that these tags are restricted to a single line
      s/\<b\>(.*?)\<\/b\>/<b>$1<\/b>/gi;
      s/\<i\>(.*?)\<\/i\>/<i>$1<\/i>/gi;
      s/\<strong\>(.*?)\<\/strong\>/<strong>$1<\/strong>/gi;
      s/\<em\>(.*?)\<\/em\>/<em>$1<\/em>/gi;
    }
    s/\<tt\>(.*?)\<\/tt\>/<tt>$1<\/tt>/gis;  # <tt> (MeatBall)
    if ($HtmlLinks) {
      s/\<A(\s[^<>]+?)\>(.*?)\<\/a\>/&StoreHref($1, $2)/gise;
    }
    if ($FreeLinks) {
      # Consider: should local free-link descriptions be conditional?
      # Also, consider that one could write [[Bad Page|Good Page]]?
      s/\[\[$FreeLinkPattern\|([^\]]+)\]\]/&StorePageOrEditLink($1, $2)/geo;
      s/\[\[$FreeLinkPattern\]\]/&StorePageOrEditLink($1, "")/geo;
    }
    if ($BracketText) {  # Links like [URL text of link]
      s/\[$UrlPattern\s+([^\]]+?)\]/&StoreBracketUrl($1, $2)/geos;
      s/\[$InterLinkPattern\s+([^\]]+?)\]/&StoreBracketInterPage($1, $2)/geos;
      if ($WikiLinks && $BracketWiki) {  # Local bracket-links
        s/\[$LinkPattern\s+([^\]]+?)\]/&StoreBracketLink($1, $2)/geos;
      }
    }
    s/\[$UrlPattern\]/&StoreBracketUrl($1, "")/geo;
    s/\[$InterLinkPattern\]/&StoreBracketInterPage($1, "")/geo;
    s/$UrlPattern/&StoreUrl($1, $useImage)/geo;
    s/$InterLinkPattern/&StoreInterPage($1)/geo;
    if ($WikiLinks) {
      s/$LinkPattern/&GetPageOrEditLink($1, "")/geo;
    }
    s/$RFCPattern/&StoreRFC($1)/geo;
    s/$ISBNPattern/&StoreISBN($1)/geo;
    if ($ThinLine) {
      s/(^|\n)\s*-------+/<hr noshade class=wikiline style="height:4px">/g; # ThinLine fix ##TAB
      s/(^|\n)\s*------+/<hr noshade class=wikiline style="height:3px">/g; # ThinLine fix ##TAB
    } else {
      s/(^|\n)\s*----+/<hr class=wikiline>/g; ##TAB
    }
  }
  if ($doLines) { # 0 = no line-oriented, 1 or 2 = do line-oriented
    # The quote markup patterns avoid overlapping tags (with 5 quotes)
    # by matching the inner quotes for the strong pattern.
    s/('*)'''(.*?)'''/$1<strong>$2<\/strong>/g;
    s/''(.*?)''/<em>$1<\/em>/g;
    if ($UseHeadings) {
      s/(^|\n)\s*(\=+)\s+([^\n]+)\s+\=+/&WikiHeading($1, $2, $3)/geo;
    }
    ## Tables:
    s/^\|([^|]*)\s*/<TR class=wikitablerow><TD class=wikitablecell>$1<\/TD>\n/g; # start of line; new table-row ## TAB
    s/\|([^|]*)\s*/<td class=wikitablecell>$1<\/td>\n/g; #table new field ## TAB
  }
  return $_;
}

sub WikiLinesToHtml {
  my ($pageText) = @_;
  my ($pageHtml, @htmlStack, $code, $depth, $oldCode);  my ($tag); #table

  @htmlStack = ();
  $depth = 0;
  $pageHtml = "";
  foreach (split(/\n/, $pageText)) {  # Process lines one-at-a-time
    $_ .= "\n";
    if (s/^(\;+)([^:]+\:?)\:/<dt>$2<dd>/) {
      $code = "DL";
      $depth = length $1;
    } elsif (s/^(\:+)/<dt><dd>/) {
      $code = "DL";
      $depth = length $1;
    } elsif (s/^(\*+)/<li>/) {
      $code = "UL";
      $depth = length $1;
    } elsif (s/^(\#+)/<li>/) {
      $code = "OL";
      $depth = length $1;
    } elsif (/^[ \t].*\S/) {
      $code = "PRE";
      $depth = 1;
    } elsif (/^[\|\+].*\S/) { #table
      $code = "TABLE"; #table
      $depth = 1; #table
    } else {
      $depth = 0;
    }
    while (@htmlStack > $depth) {   # Close tags as needed
      $tag = pop(@htmlStack); #table
      if ($tag eq "TABLE") { #table
        $pageHtml .= "</TR>\n"; #table
        $tag = "table";      } #table
      $pageHtml .= "</" . $tag . ">\n"; #table
    }
    if ($depth > 0) {
      $depth = $IndentLimit  if ($depth > $IndentLimit);
      if (@htmlStack) {  # Non-empty stack
        $oldCode = pop(@htmlStack);
        if ($oldCode ne $code) {
          $pageHtml .= "</$oldCode><$code>\n";
        }
        push(@htmlStack, $code);
      }
      while (@htmlStack < $depth) {
        push(@htmlStack, $code);
        if ($code eq "TABLE") { #table
          $pageHtml .= "<TABLE class=wikitable>\n"; #table ## TAB
        } else { #table
        $pageHtml .= "<$code>\n";
        } #table
      }
    }
    s/^\s*$/<p>\n/;                        # Blank lines become <p> tags
    $pageHtml .= &CommonMarkup($_, 1, 2);  # Line-oriented common markup
  }
  while (@htmlStack > 0) {       # Clear stack
    $pageHtml .=  "</" . pop(@htmlStack) . ">\n";
  }
  return $pageHtml;
}


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited April 9, 2009 7:20 pm by MarkusLude (diff)
Search: