diff --git a/lib/html2text.php b/lib/html2text.php index b7e3e3e9ec4..0c29cce8fd9 100644 --- a/lib/html2text.php +++ b/lib/html2text.php @@ -219,7 +219,7 @@ class html2text '-', '*', '£', - 'EUR', // Euro sign. € ? + 'EUR', // Euro sign. € ? ' ' // Runs of spaces, post-handling ); @@ -237,6 +237,7 @@ class html2text '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i', // '/<(th)[^>]*>(.*?)<\/th>/i', //
Hello world!
')); + } + + public function test_html_to_text_image() { + $this->assertEqual('[edit]', html_to_text('
'));
+ }
+
+ public function test_html_to_text_nowrap() {
+ $long = "Here is a long string, more than 75 characters long, since by default html_to_text wraps text at 75 chars.";
+ $this->assertEqual($long, html_to_text($long, 0));
+ }
}
?>
diff --git a/lib/weblib.php b/lib/weblib.php
index 1d625e13860..7e63178df31 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -2288,17 +2288,18 @@ function markdown_to_html($text) {
/**
* Given HTML text, make it into plain text using external function
*
- * @uses $CFG
* @param string $html The text to be converted.
- * @return string
+ * @param integer $width Width to wrap the text at. (optional, default 75 which
+ * is a good value for email. 0 means do not limit line length.)
+ * @return string plain text equivalent of the HTML.
*/
-function html_to_text($html) {
+function html_to_text($html, $width = 75) {
global $CFG;
require_once($CFG->libdir .'/html2text.php');
- $h2t = new html2text($html);
+ $h2t = new html2text($html, false, true, $width);
$result = $h2t->get_text();
return $result;