From d3105370870a8c51aaeb6a18f561311202da3356 Mon Sep 17 00:00:00 2001 From: alecpl Date: Mon, 11 Apr 2011 12:24:00 +0000 Subject: - Apply fixes from trunk --- program/lib/html2text.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'program/lib/html2text.php') diff --git a/program/lib/html2text.php b/program/lib/html2text.php index 325a1c941..48df4592c 100644 --- a/program/lib/html2text.php +++ b/program/lib/html2text.php @@ -572,9 +572,16 @@ class html2text */ function _convert_pre(&$text) { + // get the content of PRE element 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); + // 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 = ''; } } @@ -639,9 +646,8 @@ class html2text * * @param array PREG matches * @return string - * @access private */ - function _preg_callback($matches) + private function _preg_callback($matches) { switch($matches[1]) { case 'b': @@ -658,14 +664,24 @@ 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 * * @param string * @return string - * @access private */ - function _strtoupper($str) + private function _strtoupper($str) { if (function_exists('mb_strtoupper')) return mb_strtoupper($str); -- cgit v1.2.3