[Svn] r1695 - trunk/roundcubemail/program/lib
trac at roundcube.net
trac at roundcube.net
Fri Aug 29 10:40:21 CEST 2008
Author: alec
Date: 2008-08-29 03:40:21 -0500 (Fri, 29 Aug 2008)
New Revision: 1695
Modified:
trunk/roundcubemail/program/lib/html2text.php
Log:
- Added PRE handling in html2text class (#1484740)
Modified: trunk/roundcubemail/program/lib/html2text.php
===================================================================
--- trunk/roundcubemail/program/lib/html2text.php 2008-08-29 07:48:23 UTC (rev 1694)
+++ trunk/roundcubemail/program/lib/html2text.php 2008-08-29 08:40:21 UTC (rev 1695)
@@ -31,6 +31,7 @@
* *
*************************************************************************/
+/* 2008/08/29: Added PRE handling by A.L.E.C <alec at alec.pl> */
/**
* Takes HTML and converts it to formatted, plain text.
@@ -199,6 +200,37 @@
);
/**
+ * List of preg* regular expression patterns to search for in PRE body,
+ * used in conjunction with $pre_replace.
+ *
+ * @var array $pre_search
+ * @access public
+ * @see $pre_replace
+ */
+ $pre_search = array(
+ "/\n/",
+ "/\t/",
+ '/ /',
+ '/<pre[^>]*>/',
+ '/<\/pre>/'
+ );
+
+ /**
+ * List of pattern replacements corresponding to patterns searched for PRE body.
+ *
+ * @var array $pre_replace
+ * @access public
+ * @see $pre_search
+ */
+ $pre_replace = array(
+ '<br>',
+ ' ',
+ ' ',
+ '',
+ ''
+ );
+
+ /**
* Contains a list of HTML tags to allow in the resulting text.
*
* @var string $allowed_tags
@@ -375,6 +407,9 @@
$text = trim(stripslashes($this->html));
+ // Convert <PRE>
+ $this->_convert_pre($text);
+
// Run our defined search-and-replace
$text = preg_replace($this->search, $this->replace, $text);
@@ -444,6 +479,21 @@
return $display . ' [' . ($index+1) . ']';
}
+
+ /**
+ * Helper function for PRE body conversion.
+ *
+ * @param string HTML content
+ * @access private
+ */
+ function _convert_pre(&$text)
+ {
+ while(preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches))
+ {
+ $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]);
+ $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text);
+ }
+ }
}
-?>
\ No newline at end of file
+?>
_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn
More information about the Svn
mailing list