Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated diff functions to handle HTML formatting a little better.

  • Loading branch information...
commit ab37ddd5d2d3dc070db6e0d7ec4b95c58f08de16 1 parent 6e2c52b
mchurch authored
Showing with 23 additions and 31 deletions.
  1. +23 −31 mod/wiki/ewiki/plugins/moodle/diff.php
54 mod/wiki/ewiki/plugins/moodle/diff.php
View
@@ -34,12 +34,25 @@ function ewiki_page_stupid_diff($id, $data, $action) {
# 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 @@ function ewiki_page_stupid_diff($id, $data, $action) {
///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 @@ function ewiki_page_stupid_diff($id, $data, $action) {
}
else {
if($wiki->htmlmode == 2) {
- $o .= "$line<br>\n";
+ $o .= "$line\n";
} else {
$o .= "&nbsp; $line<br>\n";
}
Please sign in to comment.
Something went wrong with that request. Please try again.