/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if ($node->tagName === 'title') { // Also set the document title from the first heading if ($this->level === 1) { $head = $this->getHead($root); $title = $root->ownerDocument->createElement('title', htmlspecialchars(trim($node->textContent))); $head->appendChild($title); } // Create common HTML headers $header = $root->ownerDocument->createElement('h' . min(6, $this->level)); if ($this->level >= 6) { $header->setAttribute('class', 'h' . $this->level); } $root->appendChild($header); // Recurse $converter->visitChildren($node, $header); } else { ++$this->level; // Set internal cross reference target if section has an ID assigned if ($node->hasAttribute('ID')) { $target = $root->ownerDocument->createElement('a'); $target->setAttribute('name', $node->getAttribute('ID')); $root->appendChild($target); } // Recurse $converter->visitChildren($node, $root); // Reduce header level back to original state after recursion --$this->level; } return $root; }
/** * Handle a node. * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $element = $root->ownerDocument->createElement('literallayout'); $element->setAttribute('class', 'normal'); $root->parentNode->appendChild($element); // Recurse $converter->visitChildren($node, $element); // Aggregate additional line block elements if ($node->nextSibling && ($node->nextSibling->nodeType === XML_ELEMENT_NODE && $node->nextSibling->tagName === 'line' || $node->nextSibling->nodeType === XML_TEXT_NODE && trim($node->nextSibling->data) === '')) { do { if ($node->nextSibling->nodeType === XML_ELEMENT_NODE) { $element->appendChild(new DOMText("\n")); $converter->visitChildren($node->nextSibling, $element); } $node->parentNode->removeChild($node->nextSibling); } while ($node->nextSibling && ($node->nextSibling->nodeType === XML_ELEMENT_NODE && $node->nextSibling->tagName === 'line' || $node->nextSibling->nodeType === XML_TEXT_NODE && trim($node->nextSibling->data) === '')); } // If there are any siblings, put them into a new paragraph node, // "below" the list node. if ($node->nextSibling) { $newParagraph = $node->ownerDocument->createElement('paragraph'); do { $newParagraph->appendChild($node->nextSibling->cloneNode(true)); $node->parentNode->removeChild($node->nextSibling); } while ($node->nextSibling); $node->parentNode->parentNode->appendChild($newParagraph); } return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if (ezcDocumentDocbookToRstConverter::$indentation > 0) { $converter->triggerError(E_WARNING, "Indented section found, cannot be represented in RST."); } // Reset indenteation level, ever we reach a new section ezcDocumentDocbookToRstConverter::$indentation = 0; if ($node->tagName === 'title') { // Get actual title string by recursing into the title node $converter->setSkipPostDecoration(true); $title = trim($converter->visitChildren($node, '')); $converter->setSkipPostDecoration(false); // Get RST title decoration characters if (!isset($converter->options->headerTypes[$this->level])) { $converter->triggerError(E_ERROR, "No characters for title of level {$this->level} defined."); return $root . $title; } if (strlen($marker = $converter->options->headerTypes[$this->level]) > 1) { return $root . sprintf("\n%s\n%s\n%s\n\n", $marker = str_repeat($marker[0], strlen($title)), $title, $marker); } else { return $root . sprintf("\n%s\n%s\n\n", $title, str_repeat($marker, strlen($title))); } } else { ++$this->level; // Set internal cross reference target if section has an ID assigned if ($node->hasAttribute('ID')) { $root .= '.. _' . $node->getAttribute('ID') . ":\n\n"; } // Recurse $root = $converter->visitChildren($node, $root); // Reduce header level back to original state after recursion --$this->level; } return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { // Locate optional attribution elements, and transform them below the // recursive quote visiting. $xpath = new DOMXPath($node->ownerDocument); $attributionNodes = $xpath->query('*[local-name() = "attribution"]', $node); $attributions = array(); foreach ($attributionNodes as $attribution) { $attributions[] = $attribution->cloneNode(true); $attribution->parentNode->removeChild($attribution); } // Recursively decorate blockquote, after all attribution nodes are // removed ezcDocumentDocbookToRstConverter::$indentation += 4; $root = $converter->visitChildren($node, $root); // Append attribution nodes, if any foreach ($attributions as $attribution) { $converter->setSkipPostDecoration(true); $attributionLine = '-- ' . trim($converter->visitChildren($attribution, '')); $converter->setSkipPostDecoration(false); $root .= ezcDocumentDocbookToRstConverter::wordWrap($attributionLine) . "\n\n"; } ezcDocumentDocbookToRstConverter::$indentation -= 4; return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { // Do not stack paragraphs if ($root->tagName !== 'p') { $paragraph = $root->ownerDocument->createElement('p'); $root->appendChild($paragraph); $converter->visitChildren($node, $paragraph); } else { $converter->visitChildren($node, $root); } return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { // Get image resource $resource = $node->getElementsBytagName('imagedata')->item(0); $image = $root->ownerDocument->createElement('img'); // Transform attributes $attributes = array('width' => 'width', 'depth' => 'height', 'fileref' => 'src'); foreach ($attributes as $src => $dst) { if ($resource->hasAttribute($src)) { $image->setAttribute($dst, htmlspecialchars($resource->getAttribute($src))); } } // Check if the image has a description if (($textobject = $node->getElementsBytagName('textobject')) && $textobject->length > 0) { $image->setAttribute('alt', htmlspecialchars(trim($textobject->item(0)->textContent))); } else { // Always set some alt value, as this is required by XHtml $image->setAttribute('alt', htmlspecialchars($resource->getAttribute('src'))); } // Check if the image has additional description assigned. In such a // case we wrap the image and the text inside another block. if (($textobject = $node->getElementsBytagName('caption')) && $textobject->length > 0) { $textobject = $textobject->item(0); $wrapper = $root->ownerDocument->createElement('div'); $wrapper->setAttribute('class', 'image'); $wrapper->appendChild($image); // Decorate the childs of the caption node recursively, as it might // contain additional markup. $textobject = $converter->visitChildren($textobject, $wrapper); $image = $wrapper; } $root->appendChild($image); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if (!$this->deepIgnore) { return $converter->visitChildren($node, $root); } return $root; }
/** * Extract directive parameters * * Extract the image directive parameters from a media object or inline * media object node in the Docbook document. Returns an array with * named keys containing the directive parameters. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @return array */ protected function getDirectiveParameters(ezcDocumentElementVisitorConverter $converter, DOMElement $node) { // Get image resource $resource = $node->getElementsBytagName('imagedata')->item(0); $parameter = $resource->getAttribute('fileref'); $options = array(); $content = null; // Transform attributes $attributes = array('width' => 'width', 'depth' => 'height'); foreach ($attributes as $src => $dst) { if ($resource->hasAttribute($src)) { $options[$dst] = $resource->getAttribute($src); } } // Check if the image has a description if (($textobject = $node->getElementsBytagName('textobject')) && $textobject->length > 0) { $options['alt'] = trim($textobject->item(0)->textContent); } // Check if the image has additional description assigned. In such a // case we wrap the image and the text inside another block. if (($textobject = $node->getElementsBytagName('caption')) && $textobject->length > 0) { $textobject = $textobject->item(0); // Decorate the childs of the caption node recursively, as it might // contain additional markup. $content = $converter->visitChildren($textobject, ''); } // If the directive has explicit content, we render it as a figure // instead of an image. $type = $content !== null ? 'figure' : 'image'; return array('type' => $type, 'parameter' => $parameter, 'options' => $options, 'content' => $content); }
/** * Extract image parameters * * Extract the image parameters from a media object or inline media object * node in the Docbook document. Returns an array with named keys * containing the directive parameters. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @return array */ protected function getImageParameters(ezcDocumentElementVisitorConverter $converter, DOMElement $node) { $resource = $node->getElementsBytagName('imagedata')->item(0); $options = array('resource' => $resource->getAttribute('fileref')); // Get image resource // Transform attributes $attributes = array('width' => 'width', 'depth' => 'height'); foreach ($attributes as $src => $dst) { if ($resource->hasAttribute($src)) { $options[$dst] = $resource->getAttribute($src); } } // Check if the image has a description if (($textobject = $node->getElementsBytagName('textobject')) && $textobject->length > 0) { $options['alt'] = trim($textobject->item(0)->textContent); } // Check if the image has additional description assigned. In such a // case we wrap the image and the text inside another block. if (($textobject = $node->getElementsBytagName('caption')) && $textobject->length > 0) { $textobject = $textobject->item(0); // Decorate the childs of the caption node recursively, as it might // contain additional markup. $options['text'] = preg_replace('(\\s+)', ' ', $converter->visitChildren($textobject, '')); } return $options; }
/** * Handle a node. * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if ($node->hasAttribute('anchor_name')) { // This is an internal reference $link = $root->ownerDocument->createElement('link'); $link->setAttribute('linked', $node->getAttribute('anchor_name')); $root->appendChild($link); } else { switch (true) { case $node->hasAttribute('url_id'): $method = 'fetchUrlById'; $value = $node->getAttribute('url_id'); break; case $node->hasAttribute('node_id'): $method = 'fetchUrlByNodeId'; $value = $node->getAttribute('node_id'); break; case $node->hasAttribute('object_id'): $method = 'fetchUrlByObjectId'; $value = $node->getAttribute('object_id'); break; default: $converter->triggerError(E_WARNING, 'Unhandled link type.'); return $root; } $link = $root->ownerDocument->createElement('ulink'); $link->setAttribute('url', $converter->options->linkProvider->{$method}($value, $node->hasAttribute('view') ? $node->getAttribute('view') : null, $node->hasAttribute('show_path') ? $node->getAttribute('show_path') : null)); $root->appendChild($link); } $converter->visitChildren($node, $link); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $type = $this->types[$node->tagName]; $content = $converter->visitChildren($node, ''); $root .= $this->renderDirective($type, '', array(), $content); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $quote = $root->ownerDocument->createElement('blockquote'); // Locate optional attribution elements, and transform them below the // recursive quote visiting. $xpath = new DOMXPath($node->ownerDocument); $attributionNodes = $xpath->query('*[local-name() = "attribution"]', $node); $attributions = array(); foreach ($attributionNodes as $attribution) { $attributions[] = $attribution->cloneNode(true); $attribution->parentNode->removeChild($attribution); } // Recursively decorate blockquote, after all attribution nodes are // removed $quote = $converter->visitChildren($node, $quote); $root->appendChild($quote); // Append attribution nodes, if any foreach ($attributions as $attribution) { $div = $root->ownerDocument->createElement('div'); $div->setAttribute('class', 'attribution'); $quote->appendChild($div); $cite = $root->ownerDocument->createElement('cite', htmlspecialchars($attribution->textContent)); $div->appendChild($cite); } return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $p = $root->appendChild($root->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:p')); $this->styler->applyStyles($node, $p); $converter->visitChildren($node, $p); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $citationContent = trim($converter->visitChildren($node, '')); $number = $converter->appendCitation($citationContent); // Add autonumbered citation reference $root .= sprintf('[CIT%03d]_ ', $number); return $root; }
/** * Handle a node. * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $anchor = $root->ownerDocument->createElement('anchor'); $anchor->setAttribute('ID', $node->getAttribute('name')); $root->appendChild($anchor); $converter->visitChildren($node, $anchor); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $converter->setSkipPostDecoration(true); $comment = $converter->visitChildren($node, ''); $converter->setSkipPostDecoration(false); $root .= '.. ' . trim(ezcDocumentDocbookToRstConverter::wordWrap($comment, 3)) . "\n\n"; return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $footnoteContent = trim($converter->visitChildren($node, '')); $number = $converter->appendFootnote($footnoteContent); // Add autonumbered footnote reference $root .= '[#]_ '; return $root; }
/** * Handle a node. * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { foreach ($node->childNodes as $child) { if ($child->nodeType === XML_ELEMENT_NODE && $child->tagName === 'varlistentry') { $term = $child->getElementsByTagName('term')->item(0); $root .= ezcDocumentDocbookToRstConverter::wordWrap(trim($converter->visitChildren($term, ''))) . "\n"; ezcDocumentDocbookToRstConverter::$indentation += 4; foreach ($child->childNodes as $subChild) { if ($subChild->nodeType === XML_ELEMENT_NODE && $subChild->tagName === 'listitem') { $root = $converter->visitChildren($subChild, $root); } } ezcDocumentDocbookToRstConverter::$indentation -= 4; } } return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $link = $root->ownerDocument->createElement('a'); $link->setAttribute('href', '#' . $node->getAttribute('linked')); $root->appendChild($link); $converter->visitChildren($node, $link); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { // Reset indenteation level, ever we reach a new section ezcDocumentDocbookToWikiConverter::$indentation = 0; if ($node->tagName === 'title') { // Get actual title string by recursing into the title node $title = trim($converter->visitChildren($node, '')); return $root . sprintf("\n%s %s\n\n", str_repeat("=", $this->level + 1), $title); } else { ++$this->level; // Recurse $root = $converter->visitChildren($node, $root); // Reduce header level back to original state after recursion --$this->level; } return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $paragraph = $root->ownerDocument->createElement('paragraph'); $root->appendChild($paragraph); $table = $root->ownerDocument->createElement('table'); $paragraph->appendChild($table); $converter->visitChildren($node, $table); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if ($node->hasAttribute('Role') && $node->getAttribute('Role') === 'strong') { $marker = '**'; } else { $marker = '*'; } return $root . ' ' . $marker . $converter->visitChildren($node, '') . $marker; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $type = $this->types[$node->tagName]; $paragraph = $root->ownerDocument->createElement('p'); $paragraph->setAttribute('class', $type); $root->appendChild($paragraph); $converter->visitChildren($node, $paragraph); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $a = $root->appendChild($root->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TEXT, 'text:a')); $a->setAttributeNS(ezcDocumentOdt::NS_XLINK, 'xlink:type', 'simple'); $a->setAttributeNS(ezcDocumentOdt::NS_XLINK, 'xlink:href', $node->getAttribute('url')); $this->styler->applyStyles($node, $a); $converter->visitChildren($node, $a); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { // Visit paragraph contents $contents = $converter->visitChildren($node, ''); // Remove all line breaks inside the paragraph. $contents = trim(preg_replace('(\\s+)', ' ', $contents)); $root .= ezcDocumentDocbookToWikiConverter::wordWrap($contents) . "\n\n"; return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $element = $root->ownerDocument->createElement('table'); $root->appendChild($element); // Handle attributes // Recurse $converter->visitChildren($node, $element); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $header = $root->ownerDocument->createElement('header'); $root->appendChild($header); if ($node->hasAttribute('ID')) { $header->setAttribute('anchor_name', $node->getAttribute('ID')); } $converter->visitChildren($node, $header); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { $cell = $root->ownerDocument->createElement('td'); if ($node->hasAttribute('morerows')) { $cell->setAttribute('rowspan', $node->getAttribute('morerows') + 1); } $root->appendChild($cell); $converter->visitChildren($node, $cell); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { ezcDocumentDocbookToRstConverter::$indentation += 2; foreach ($node->childNodes as $child) { if ($child->nodeType === XML_ELEMENT_NODE && $child->tagName === 'listitem') { $root .= str_repeat(' ', max(0, ezcDocumentDocbookToRstConverter::$indentation - 2)) . $converter->options->itemListCharacter . ' ' . trim($converter->visitChildren($child, '')) . "\n\n"; } } ezcDocumentDocbookToRstConverter::$indentation = max(0, ezcDocumentDocbookToRstConverter::$indentation - 2); return $root; }
/** * Handle a node * * Handle / transform a given node, and return the result of the * conversion. * * @param ezcDocumentElementVisitorConverter $converter * @param DOMElement $node * @param mixed $root * @return mixed */ public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root) { if ($node->hasAttribute('Role') && $node->getAttribute('Role') === 'strong') { $emphasis = $root->ownerDocument->createElement('strong'); } else { $emphasis = $root->ownerDocument->createElement('emphasize'); } $root->appendChild($emphasis); $converter->visitChildren($node, $emphasis); return $root; }