From 1a94ebd72bd8da7c33633f7f607372b20a01e135 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 2 Sep 2010 11:56:00 -0600 Subject: [PATCH] Html2text filter will use horde/Text_Filter, if available, to wrap text --- .../Text_Filter/lib/Horde/Text/Filter/Html2text.php | 17 +++++++++++++++-- framework/Text_Filter/package.xml | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php b/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php index e9affe56e..693dd014f 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php @@ -79,6 +79,7 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base { $this->_indent = 0; $this->_linkList = array(); + $this->_params['_bq'] = false; return $text; } @@ -95,8 +96,10 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base try { $dom = new Horde_Domhtml($text, $this->_params['charset']); $text = Horde_String::convertCharset($this->_node($dom->dom, $dom->dom), null, $this->_params['charset']); + $dom_convert = true; } catch (Exception $e) { $text = strip_tags(preg_replace("/\/i", "\n", $text)); + $dom_convert = false; } /* Bring down number of empty lines to 2 max, and remove trailing @@ -105,7 +108,15 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base /* Wrap the text to a readable format. */ if ($this->_params['width']) { - $text = wordwrap($text, $this->_params['width']); + if ($dom_convert && + $this->_params['_bq'] && + class_exists('Horde_Text_Flowed')) { + $flowed = new Horde_Text_Flowed($text, $this->_params['charset']); + $flowed->setOptLength($this->_params['width']); + $text = $flowed->toFlowed(); + } else { + $text = wordwrap($text, $this->_params['width']); + } } /* Add link list. */ @@ -216,9 +227,11 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base break; case 'blockquote': + $this->_params['_bq'] = true; foreach (explode("\n", $this->_node($doc, $child)) as $line) { $quote = '>'; - if (($line[0] != '>') && + if ($line && + ($line[0] != '>') && ($line[0] != ' ' || $line[0] != "\t")) { $quote .= ' '; } diff --git a/framework/Text_Filter/package.xml b/framework/Text_Filter/package.xml index a5d26df71..0e6129cf1 100644 --- a/framework/Text_Filter/package.xml +++ b/framework/Text_Filter/package.xml @@ -34,7 +34,8 @@ beta LGPL - * Add callback parameter to the Html2text filter. + * Html2text filter will use horde/Text_Filter, if available, to wrap text. + * Add callback parameter to the Html2text filter. * XSS filter now uses PHP DOM parser to process incoming text. * Remove Horde/Core dependency. * Add Horde_Text_Filter_Exception::. @@ -122,6 +123,10 @@ Text_Filter_Csstidy pear.horde.org + + Text_Flowed + pear.horde.org + dom -- 2.11.0