Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-30741 Fix the handling of PRE tags with the latest code from upst…

  • Loading branch information...
commit 75e50ca6613a577b28b04ce901ae9dcdee50fbd9 1 parent 6508da4
@jfilip jfilip authored
Showing with 20 additions and 3 deletions.
  1. +20 −3 lib/html2text.php
View
23 lib/html2text.php
@@ -543,9 +543,15 @@ function _build_link_list( $link, $display )
*/
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, 1);
+ while (preg_match('/<pre[^>]*>(.*)<\/pre>/ismU', $text, $matches)) {
+ // convert the content
+ $this->pre_content = sprintf('<div><br>%s<br></div>',
+ 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[^>]*>.*<\/pre>/ismU',
+ array('html2text', '_preg_pre_callback'), $text, 1);
+ // free memory
+ $this->pre_content = '';
}
}
@@ -574,6 +580,17 @@ function _preg_callback($matches)
}
/**
+ * 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 $str
Please sign in to comment.
Something went wrong with that request. Please try again.