/** * 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) { 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; }
/** * Initialize destination document * * Initialize the structure which the destination document could be build * with. This may be an initial DOMDocument with some default elements, or * a string, or something else. * * @return mixed */ protected function initializeDocument() { self::$indentation = 0; self::$wordWrap = $this->options->wordWrap; return ''; }