/**
* Takes HTML and converts it to formatted, plain text.
*
- * Parameters:
+ * Optional parameters to constructor:
* <pre>
- * charset - (string) The charset to use for html_entity_decode() calls.
+ * callback - (callback) Callback triggered on every node. Passed the
+ * DOMDocument object and the DOMNode object. If the callback
+ * returns non-null, add this text to the output and skip further
+ * processing of the node.
+ * charset - (string) The charset of the text.
* width - (integer) The wrapping width. Set to 0 to not wrap.
* </pre>
*
* @var array
*/
protected $_params = array(
+ 'callback' => null,
'charset' => 'UTF-8',
'width' => 75
);
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
+ if ($this->_params['callback'] &&
+ ($txt = call_user_func($this->_params['callback'], $doc, $child)) !== null) {
+ $out .= $txt;
+ continue;
+ }
+
if ($child instanceof DOMElement) {
switch (strtolower($child->tagName)) {
case 'h1':
if (!$child->nextSibling) {
$tmp = rtrim($tmp);
}
- $out .= html_entity_decode($tmp, ENT_QUOTES, $this->_params['charset']);
+ $out = $tmp;
}
}
}
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
-* XSS filter now uses PHP DOM parser to process incoming text.
+ <notes> * 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::.
* Html2text converter now uses XML parser to generate output.