function filter_dom_serialize_escape_cdata_element in Mail System 6.2
Adds comments around the <!CDATA section in a dom element.
DOMDocument::loadHTML in filter_dom_load() makes CDATA sections from the contents of inline script and style tags. This can cause HTML 4 browsers to throw exceptions.
This function attempts to solve the problem by creating a DocumentFragment and immitating the behavior in drupal_get_js(), commenting the CDATA tag.
Parameters
$dom_document: The DOMDocument containing the $dom_element.
$dom_element: The element potentially containing a CDATA node.
$comment_start: String to use as a comment start marker to escape the CDATA declaration.
$comment_end: String to use as a comment end marker to escape the CDATA declaration.
1 call to filter_dom_serialize_escape_cdata_element()
- filter_dom_serialize in ./
html_to_text.inc - Converts a DOM object back to an HTML snippet.
File
- ./
html_to_text.inc, line 818 - Copy of drupal_html_to_text improvements from issue #299138.
Code
function filter_dom_serialize_escape_cdata_element($dom_document, $dom_element, $comment_start = '//', $comment_end = '') {
foreach ($dom_element->childNodes as $node) {
if (get_class($node) == 'DOMCdataSection') {
// See drupal_get_js(). This code is more or less duplicated there.
$embed_prefix = "\n<!--{$comment_start}--><![CDATA[{$comment_start} ><!--{$comment_end}\n";
$embed_suffix = "\n{$comment_start}--><!]]>{$comment_end}\n";
$fragment = $dom_document
->createDocumentFragment();
$fragment
->appendXML($embed_prefix . $node->data . $embed_suffix);
$dom_element
->appendChild($fragment);
$dom_element
->removeChild($node);
}
}
}