From 75e50ca6613a577b28b04ce901ae9dcdee50fbd9 Mon Sep 17 00:00:00 2001 From: Justin Filip Date: Wed, 14 Dec 2011 11:36:40 -0500 Subject: [PATCH] MDL-30741 Fix the handling of PRE tags with the latest code from upstream: http://trac.roundcube.net/browser/trunk/roundcubemail/program/lib/html2text.php?rev=5497 --- lib/html2text.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/html2text.php b/lib/html2text.php index 9cc213ddd60..e360b2c47d2 100644 --- a/lib/html2text.php +++ b/lib/html2text.php @@ -543,9 +543,15 @@ class html2text */ function _convert_pre(&$text) { - while(preg_match('/]*>(.*)<\/pre>/ismU', $text, $matches)) { - $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]); - $text = preg_replace('/]*>.*<\/pre>/ismU', '

' . $result . '
', $text, 1); + while (preg_match('/]*>(.*)<\/pre>/ismU', $text, $matches)) { + // convert the content + $this->pre_content = sprintf('

%s
', + preg_replace($this->pre_search, $this->pre_replace, $matches[1])); + // replace the content (use callback because content can contain $0 variable) + $text = preg_replace_callback('/]*>.*<\/pre>/ismU', + array('html2text', '_preg_pre_callback'), $text, 1); + // free memory + $this->pre_content = ''; } } @@ -573,6 +579,17 @@ class html2text } } + /** + * Callback function for preg_replace_callback use in PRE content handler. + * + * @param array PREG matches + * @return string + */ + private function _preg_pre_callback($matches) + { + return $this->pre_content; + } + /** * Strtoupper multibyte wrapper function *