[Home]WikiPatches/TagBlankLines

UseModWiki | WikiPatches | RecentChanges | Preferences

I have implemented the "Alternative Solution 2" further down on this page as an option ($ParseParas?) for 1.0. It defaults to 0, which uses the old wiki code. --CliffordAdams
Use matched <P>...</P> for paragraphs, avoid tagging blank lines with solitary <P>. lines with solitary <P>.

This patch attempts (I'm new at this patching business) to repair the following conditions:

This patch inserts a <P> tag at the top of the file if the first line is not otherwise marked up. It also inserts <P> tags in blank lines only if the blank line is not followed by a markup tag. It closes <P> tags with </P> appropriately.

At the end of sub WikiLinesToHtml, insert patch "jer" as follows just above the return:

  #jer------------
  $pageHtml =~ s/^([A-Za-z0-9])/<p>$1/; # Start with <p> if needed
  $pageHtml =~ s/\n\s*\n([A-Za-z0-9])/<\/p>\n<p>$1/g; # Close and open <p> on blank lines
  $pageHtml =~ s/(\n<p>.*?\n)(\s*\n<)/$1<\/p>\n</g; # Close on blank if next is <
  $pageHtml =~ s/(<\/pre>|<\/p>)\s*\n<\/p>/$1\n/ig; # Remove duped closing tags
  #jer end

  return $pageHtml;

A little above that, comment-out the blank line conversion as follows:

    #s/^\s*$/<p>\n/;      # Blank lines become <p> tags

I am currently testing this on a hidden wiki with giddily encouraging results. -- JerryMuelver


Alternative solution 1

I have a different method. I defined a variable called $BreakLines? in use vars, then I declare it as follows:
$BreakLines  = 1;	# 1 = every cr in text is a <br> in html , 0 = old compatible code
Then in WikiLinesToHtml I changed
    s/^\s*$/<p>\n/;      # Blank lines become <p> tags
to
    if ($BreakLines) {
        s/^\s*$/<br>/;                   # Blank lines become <br> tags
    } else {
        s/^\s*$/<p>\n/;                    # Blank lines become <p> tags
    }

This makes my site look nice. I'm not sure if it fixes all of the problems you encountered above. -Chris Tulino


Alternative solution 2

I have a better, more generalized solution.

1166,1167c1166,1167
<   $pageText =~ s/((.|\n)+?\n)\s*\n/&ParseParagraph($1)/geo;
<   $pageText =~ s/(.*)<\/p>(.+)$/$1.&ParseParagraph($2)/seo;
---
>   $pageText = &CommonMarkup($pageText, 1, 0);   # Multi-line markup
>   $pageText = &WikiLinesToHtml($pageText);      # Line-oriented markup
1171,1179c1171,1172
< }
<
< sub ParseParagraph {
<   my ($text) = @_;
<   $text = &CommonMarkup($text, 1, 0);   # Multi-line markup
<   $text = &WikiLinesToHtml($text);      # Line-oriented markup
<   return "<p>$text</p>\n";
< }
<
---
> }
>
1294c1287
<     #s/^\s*$/<p>\n/;                        # Blank lines become <p> tags
---
>     s/^\s*$/<p>\n/;                        # Blank lines become <p> tags

I am not testing this patch well, but it seems working for me so far. I am also currently working on make UseMod compatible XHTML, which seems a lot of works. --TakuyaMurata


Am I right in thinking that alternative 2 is now part of 1.0, controlled by setting $ParseParas? to 1? --jw
Yes. (See the top of this page, which was there before this edit. :-) This option hasn't been tested much, but it helps a little. (UseModWiki has other HTML problems, and is not likely to pass strict validators anytime soon.) --CliffordAdams

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited September 23, 2007 2:19 pm by JuanmaMP (diff)
Search: