コード例 #1
0
 /**
  * @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();
 }
コード例 #2
0
ファイル: paragraph.php プロジェクト: axelmdev/ecommerce
 /**
  * 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;
 }
コード例 #3
0
ファイル: handler.php プロジェクト: bmdevel/ezc
 /**
  * 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;
 }
コード例 #4
0
ファイル: section.php プロジェクト: jordanmanning/ezpublish
 /**
  * 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;
 }
コード例 #5
0
ファイル: wiki.php プロジェクト: 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();
 }
コード例 #6
0
ファイル: wiki.php プロジェクト: jackalope/jr_cr_demo
 /**
  * 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();
 }
コード例 #7
0
ファイル: docbook_wiki.php プロジェクト: bmdevel/ezc
 /**
  * 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 '';
 }