/**
  * @dataProvider getTestDocuments
  */
 public function testLoadXmlDocumentFromFile($from, $to)
 {
     if (!is_file($to)) {
         $this->markTestSkipped("Comparision file '{$to}' not yet defined.");
     }
     $doc = new ezcDocumentDocbook();
     $doc->loadFile($from);
     $converter = new ezcDocumentDocbookToWikiConverter();
     $created = $converter->convert($doc);
     $this->assertTrue($created instanceof ezcDocumentWiki);
     // Store test file, to have something to compare on failure
     $tempDir = $this->createTempDir('docbook_rst_') . '/';
     file_put_contents($tempDir . basename($to), $text = $created->save());
     $this->assertTrue(($errors = $created->validateString($text)) === true, is_array($errors) ? implode(PHP_EOL, $errors) : 'Expected true');
     $this->assertEquals(file_get_contents($to), $text);
     // Remove tempdir, when nothing failed.
     $this->removeTempDir();
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * Render a directive
  *
  * Render a directive with the given paramters.
  *
  * @param string $name
  * @param string $parameter
  * @param array $options
  * @param string $content
  * @return string
  */
 protected function renderDirective($name, $parameter, array $options, $content = null)
 {
     $indentation = str_repeat(' ', ezcDocumentDocbookToWikiConverter::$indentation);
     // Show directive with given parameters
     $directive = sprintf("\n%s.. %s:: %s\n", $indentation, $name, $parameter);
     // Append options
     foreach ($options as $key => $value) {
         $directive .= sprintf("%s   :%s: %s\n", $indentation, ezcDocumentDocbookToWikiConverter::escapeWikiText($key), ezcDocumentDocbookToWikiConverter::escapeWikiText($value));
     }
     // Append content, if given
     if ($content !== null) {
         $directive .= "\n" . str_repeat(' ', ezcDocumentDocbookToWikiConverter::$indentation + 3) . trim(ezcDocumentDocbookToWikiConverter::wordWrap($content, 3)) . "\n";
     }
     // Append an additional newline after the directive contents
     $directive .= "\n";
     return $directive;
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
File: wiki.php Project: bmdevel/ezc
 /**
  * Create document from docbook document
  *
  * A document of the docbook format is provided and the internal document
  * structure should be created out of this.
  *
  * This method is required for all formats to have one central format, so
  * that each format can be compiled into each other format using docbook as
  * an intermediate format.
  *
  * You may of course just call an existing converter for this conversion.
  *
  * @param ezcDocumentDocbook $document
  * @return void
  */
 public function createFromDocbook(ezcDocumentDocbook $document)
 {
     if ($this->options->validate && $document->validateString($document) !== true) {
         $this->triggerError(E_WARNING, "You try to convert an invalid docbook document. This may lead to invalid output.");
     }
     $this->path = $document->getPath();
     $converter = new ezcDocumentDocbookToWikiConverter();
     $converter->options->errorReporting = $this->options->errorReporting;
     $this->contents = $converter->convert($document)->save();
 }
Example #6
0
 /**
  * Create document from docbook document
  *
  * A document of the docbook format is provided and the internal document
  * structure should be created out of this.
  *
  * This method is required for all formats to have one central format, so
  * that each format can be compiled into each other format using docbook as
  * an intermediate format.
  *
  * You may of course just call an existing converter for this conversion.
  * 
  * @param ezcDocumentDocbook $document 
  * @return void
  */
 public function createFromDocbook(ezcDocumentDocbook $document)
 {
     $converter = new ezcDocumentDocbookToWikiConverter();
     $converter->options->errorReporting = $this->options->errorReporting;
     $this->contents = $converter->convert($document)->save();
 }
Example #7
0
 /**
  * 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 '';
 }