You are here

function entity_embed_serialize in Entity Embed 7.2

Same name and namespace in other branches
  1. 7.3 includes/entity_embed.html.inc \entity_embed_serialize()
  2. 7 includes/entity_embed.html.inc \entity_embed_serialize()

Converts the body of a \DOMDocument back to an HTML snippet.

The function serializes the body part of a \DOMDocument back to an (X)HTML snippet. The resulting (X)HTML snippet will be properly formatted to be compatible with HTML user agents.

Parameters

\DOMDocument $document: A \DOMDocument object to serialize, only the tags below the first <body> node will be converted.

Return value

string A valid (X)HTML snippet, as a string.

2 calls to entity_embed_serialize()
_entity_embed_filter_align in ./entity_embed.module
Implements callback_filter_process().
_entity_embed_render_placeholders in ./entity_embed.module
Implements callback_filter_process().

File

includes/entity_embed.html.inc, line 94
DOM processing functions.

Code

function entity_embed_serialize(\DOMDocument $document) {
  $body_node = $document
    ->getElementsByTagName('body')
    ->item(0);
  $html = '';
  foreach ($body_node
    ->getElementsByTagName('script') as $node) {
    entity_embed_escape_cdata_element($node);
  }
  foreach ($body_node
    ->getElementsByTagName('style') as $node) {
    entity_embed_escape_cdata_element($node, '/*', '*/');
  }
  foreach ($body_node->childNodes as $node) {
    $html .= $document
      ->saveXML($node);
  }
  return $html;
}