Updated diff functions to handle HTML formatting a little better.

This commit is contained in:
mchurch
2004-08-25 20:31:30 +00:00
parent 6e2c52bad7
commit ab37ddd5d2
+23 -31
View File
@@ -34,12 +34,25 @@
# Different handling for html: closes Bug #1530 - Wiki diffs useless when using HTML editor
if($wiki->htmlmode==2) {
$htmlendings=array("<br />","<br>","<p>","</p>","<p />","<hr />","<hr>","</li>","</tr>");
/// Replace <p>&nbsp;</p>
$content0=preg_replace("+<p>&nbsp;</p>+i","\n",$data0["content"]);
$content0=preg_replace("+(".join("|",$htmlendings).")+","\n",$content0);
$content=preg_replace("+<p>&nbsp;</p>+i","\n",$data["content"]);
$content=preg_replace("+(".join("|",$htmlendings).")+","\n",$content);
/// Remove all new line characters. They will be placed at HTML line breaks.
$content0 = preg_replace('/\n|\r/i', ' ', $data0['content']);
$content0 = preg_replace('/(\S)\s+(\S)/', '$1 $2', $content0); // Remove multiple spaces.
$content = preg_replace('/\n|\r/i', ' ', $data['content']);
$content = preg_replace('/(\S)\s+(\S)/', '$1 $2', $content);
/// Replace <p>&nbsp;</p>
$content0 = preg_replace('#(<p.*>(&nbsp;|\s+)</p>|<p.*></p>)#i', "\n", $content0);
$content = preg_replace('#(<p.*>(&nbsp;|\s+)</p>|<p.*></p>)#i', "\n", $content);
/// Place new line characters at logical HTML positions.
$htmlendings = array('+(<br.*>)+iU', '+(<p.*>)+iU', '+(</p>)+i', '+(<hr.*>)+iU', '+(<ol.*>)+iU',
'+(</ol>)+i', '+(<ul.*>)+iU', '+(</ul>)+i', '+(<li.*>)+iU', '+(</li>)+i',
'+(</tr>)+i', '+(<div.*>)+iU', '+(</div>)+i');
$htmlrepl = array("\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n",
"\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n", "\n\$1\n",
"\n\$1\n", "\n\$1\n", "\n\$1\n");
$content0 = preg_replace($htmlendings, $htmlrepl, $content0);
$content = preg_replace($htmlendings, $htmlrepl, $content);
} else {
$content0=$data0["content"];
$content=$data["content"];
@@ -58,34 +71,13 @@
///print "</pre>";
///exit;
/// Remove empty lines in html
if($wiki->htmlmode==2) {
$html0=$txt0;
$html2=$txt2;
$txt0=array();
$txt2=array();
for($i=0;$i<count($html0);$i++) {
# $linecontent=trim(strip_tags(preg_replace("+&nbsp;+","",$html0[$i])));
# if($linecontent) { // There is something !
$txt0[]=$html0[$i];
# }
}
for($i=0;$i<count($html2);$i++) {
# $linecontent=trim(strip_tags(preg_replace("+&nbsp;+","",$html2[$i])));
# if($linecontent) { // There is something !
$txt2[]=$html2[$i];
# }
}
}
$diff0 = array_diff($txt0, $txt2);
$diff2 = array_diff($txt2, $txt0);
foreach ($txt2 as $i => $line) {
if($wiki->htmlmode != 2) {
$line = htmlentities($line);
}
// if($wiki->htmlmode != 2) {
// $line = htmlentities($line);
// }
$i2 = $i;
while ($rm = $diff0[$i2++]) {
if($wiki->htmlmode == 2) {
@@ -105,7 +97,7 @@
}
else {
if($wiki->htmlmode == 2) {
$o .= "$line<br>\n";
$o .= "$line\n";
} else {
$o .= "&nbsp; $line<br>\n";
}