85,126c85
<     $difflines = explode("\n",$v."\n");
<     $in=array(); $out=array(); $dtype='';
<     foreach($difflines as $d) {
<       if ($d>'') {
<         if ($d[0]=='-' || $d[0]=='\\') continue;
<         if ($d[0]=='<') { $out[]=substr($d,2); continue; }
<         if ($d[0]=='>') { $in[]=substr($d,2); continue; }
<       }
<       if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/",
<           $dtype,$match)) {
<         if (@$match[7]>'') {
<           $lines='lines';
<           $count=$match[1].'-'.($match[1]+$match[7]-$match[5]);
<         } elseif ($match[3]>'') {
<           $lines='lines'; $count=$match[1].'-'.$match[3];
<         } else { $lines='line'; $count=$match[1]; }
<         if ($match[4]=='a' || $match[4]=='c') {
<           $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]);
<           $FmtV['$DiffLines'] = $count;
<           echo FmtPageName($txt,$pagename);
<           if ($DiffShow['source']=='y') 
<             echo "<div class='diffmarkup'>",
<               str_replace("\n","<br />",htmlspecialchars(join("\n",$in))),
<               "</div>";
<           else echo MarkupToHTML($pagename,
<             preg_replace('/\\(:.*?:\\)/e',"Keep(htmlspecialchars(PSS('$0')))", join("\n",$in)));
<         }
<         if ($match[4]=='d' || $match[4]=='c') {
<           $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]);
<           $FmtV['$DiffLines'] = $count;
<           echo FmtPageName($txt,$pagename);
<           if ($DiffShow['source']=='y') 
<             echo "<div class='diffmarkup'>",
<               str_replace("\n","<br />",htmlspecialchars(join("\n",$out))),
<               "</div>";
<           else echo MarkupToHTML($pagename,
<             preg_replace('/\\(:.*?:\\)/e',"Keep(htmlspecialchars(PSS('$0')))",join("\n",$out)));
<         }
<         echo FmtPageName($DiffEndDelAddFmt,$pagename);
<       }
<       $in=array(); $out=array(); $dtype=$d;
<     }
---
>     echo RenderDiff($pagename, $v);
143a103,153
> ## Takes a diff string and returns an html rendering 
> ## for that diff string.
> function RenderDiff($pagename, $diff, $restorelink = 1) {
>   global $FmtV, $DiffDelFmt, $DiffAddFmt, $DiffShow,
>     $DiffEndDelAddFmt;
> 
>   $htmlout = "";
>   $difflines = explode("\n",$diff."\n");
>   $in=array(); $out=array(); $dtype='';
>   foreach($difflines as $d) {
>     if ($d>'') {
>       if ($d[0]=='-' || $d[0]=='\\') continue;
>       if ($d[0]=='<') { $out[]=substr($d,2); continue; }
>       if ($d[0]=='>') { $in[]=substr($d,2); continue; }
>     }
>     if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/",
>         $dtype,$match)) {
>       if (@$match[7]>'') {
>         $lines='lines';
>         $count=$match[1].'-'.($match[1]+$match[7]-$match[5]);
>       } elseif ($match[3]>'') {
>         $lines='lines'; $count=$match[1].'-'.$match[3];
>       } else { $lines='line'; $count=$match[1]; }
>       if ($match[4]=='a' || $match[4]=='c') {
>         $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]);
>         $FmtV['$DiffLines'] = $count;
>         $htmlout .= FmtPageName($txt,$pagename);
>         if ($DiffShow['source']=='y') 
>           $htmlout .= "<div class='diffmarkup'>".
>             str_replace("\n","<br />",htmlspecialchars(join("\n",$in))).
>             "</div>";
>         else $htmlout .= MarkupToHTML($pagename,
>           preg_replace('/\\(:.*?:\\)/e',"Keep(htmlspecialchars(PSS('$0')))", join("\n",$in)));
>       }
>       if ($match[4]=='d' || $match[4]=='c') {
>         $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]);
>         $FmtV['$DiffLines'] = $count;
>         $htmlout .= FmtPageName($txt,$pagename);
>         if ($DiffShow['source']=='y') 
>           $htmlout .= "<div class='diffmarkup'>".
>             str_replace("\n","<br />",htmlspecialchars(join("\n",$out))).
>             "</div>";
>         else $htmlout .= MarkupToHTML($pagename,
>           preg_replace('/\\(:.*?:\\)/e',"Keep(htmlspecialchars(PSS('$0')))",join("\n",$out)));
>       }
>       $htmlout .= FmtPageName($DiffEndDelAddFmt,$pagename);
>     }
>     $in=array(); $out=array(); $dtype=$d;
>   }
>   return $htmlout;
> }