Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.265 diff -u -r1.265 filter.module --- modules/filter/filter.module 2 Aug 2009 15:44:08 -0000 1.265 +++ modules/filter/filter.module 7 Aug 2009 12:14:22 -0000 @@ -571,6 +571,41 @@ return $tips; } +/** + * Converts a string into a DOM object. + * @param $text + * The text to load. + * @return + * The DOM object. + */ +function filter_dom_load($text) { + // Ignore warnings during HTML soup loading. + $htmlDom = @DOMDocument::loadHTML('' . $text . ''); + + return $htmlDom; +} + +/** + * Converts a DOM object back to a string. + * @param $htmlDom + * The DOM object to convert. + * @return + * The HTML code as a string. + */ +function filter_dom_serialize($htmlDom) { + // The result of DOMDocument->saveXML($bodyNode) is a partial (X)HTML document. + // We only need what is inside the body tag. + $bodyNode = $htmlDom->getElementsByTagName('body')->item(0); + if (preg_match("|^]*>(.*)$|s", $htmlDom->saveXML($bodyNode), $matches)) { + $body_content = $matches[1]; + // The XHTML guidelines recommend to include a space before the trailing / + // and > of empty elements for better rendering on HTML user agents. + return preg_replace('|<([^>]*)/>|i', '<$1 />', $body_content); + } + else { + return ''; + } +} /** * Format a link to the more extensive filter tips. @@ -757,21 +792,8 @@ * Scan input and make sure that all HTML tags are properly closed and nested. */ function _filter_htmlcorrector($text) { - // Ignore warnings during HTML soup loading. - $htmlDom = @DOMDocument::loadHTML('' . $text . ''); - - // The result of DOMDocument->saveXML($bodyNode) is a partial (X)HTML document. - // We only need what is inside the body tag. - $bodyNode = $htmlDom->getElementsByTagName('body')->item(0); - if (preg_match("|^]*>(.*)$|s", $htmlDom->saveXML($bodyNode), $matches)) { - $body_content = $matches[1]; - // The XHTML guidelines recommend to include a space before the trailing / - // and > of empty elements for better rendering on HTML user agents. - return preg_replace('|<([^>]*)/>|i', '<$1 />', $body_content); - } - else { - return ''; - } + $htmlDom = filter_dom_load($text); + return filter_dom_serialize($htmlDom); } /**