Somes improvements in the html style parser
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Fri, 19 Oct 2007 09:51:15 +0000 (09:51 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:35:50 +0000 (00:35 +0100)
 Changelog                   |    5 +++++
 banana/message.func.inc.php |   14 +++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@277 9869982d-c50d-0410-be91-f2a2ec7c7c7b

Changelog
banana/message.func.inc.php

index 6a216ee..a2b260f 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,8 @@
+Fri, 19 Oct 2007                                       Florent Bruneau <florent.bruneau@m4x.org>
+
+    * Rendering improvements
+
+
 ================================================================================
 VERSION 1.7
 
index 0d29f64..3b00c9c 100644 (file)
@@ -298,15 +298,15 @@ function banana_cleanStyles($tag, $attributes)
     } else {
         $style = '';
     }
-    $attributes = str_replace("\n", ' ', stripslashes($attributes));
-    $attributes = str_replace('= "', '="', $attributes);
+    $attributes = str_replace(array("\n", "\r"), ' ', stripslashes($attributes));
+    $attributes = str_replace(array('= "', '= \''), array('="', '=\''), $attributes);
     foreach ($conv as $att=>$stl) {
         $pattern = '/\b' . preg_quote($att, '/') . '=([\'"])?(.+?)(?(1)\1|(?:$| ))/i';
         if (preg_match($pattern, $attributes, $matches)) {
             $attributes = preg_replace($pattern, '', $attributes);
             $val = $matches[2];
             if ($att == 'cellspacing' && strpos($style, 'border-collapse') === false) {
-                $style .= "border-collapse: separate; border-spacing: $val $val; ";
+                $style = "border-collapse: separate; border-spacing: $val $val; " . $style;
             } elseif ($att == 'cellpadding' && $tag == 'table') {
                 $td_style[0] = "$stl: {$val}px; ";
             } elseif ($att == 'style') {
@@ -314,11 +314,11 @@ function banana_cleanStyles($tag, $attributes)
                 $style .= "$val; ";
             } elseif ($att == 'size') {
                 $val = $size_conv[$val];
-                $style .= "$stl: $val; ";
+                $style = "$stl: $val; " . $style;
             } elseif (is_numeric($val)) {
-                $style .= "$stl: {$val}px; ";
+                $style = "$stl: {$val}px; " . $style;
             } else {
-                $style .= "$stl: $val; ";
+                $style = "$stl: $val; " . $style;
             }
         }
     }
@@ -406,7 +406,7 @@ function banana_cleanHtml($source, $to_xhtml = false)
 
     // Use inlined style instead of old html attributes
     if ($to_xhtml) {
-        $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/uise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source);
+        $source = preg_replace('/<(\/?\w+)(.*?)(\/?>)/muise', "'<\\1' . banana_cleanStyles('\\1', '\\2') . '\\3'", $source);
     }    
     return preg_replace('/<(.*?)>/ie', "'<'.banana_removeEvilAttributes('\\1').'>'", $source);
 }