コード例 #1
0
ファイル: blockquote.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)
 {
     // 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;
 }
コード例 #2
0
ファイル: section.php プロジェクト: bmdevel/ezc
 /**
  * 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;
 }
コード例 #3
0
ファイル: comment.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)
 {
     $converter->setSkipPostDecoration(true);
     $comment = $converter->visitChildren($node, '');
     $converter->setSkipPostDecoration(false);
     $root .= '.. ' . trim(ezcDocumentDocbookToRstConverter::wordWrap($comment, 3)) . "\n\n";
     return $root;
 }
コード例 #4
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 ezcDocumentDocbookToRstConverter();
     $created = $converter->convert($doc);
     $this->assertTrue($created instanceof ezcDocumentRst);
     // 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();
 }
コード例 #5
0
ファイル: itemized_list.php プロジェクト: bmdevel/ezc
 /**
  * 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;
 }
コード例 #6
0
ファイル: head.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)
 {
     foreach ($this->headerMapping as $tagName => $metaName) {
         if (($nodes = $node->getElementsBytagName($tagName)) && $nodes->length > 0) {
             foreach ($nodes as $child) {
                 $root .= ":{$metaName}:\n";
                 $root .= ezcDocumentDocbookToRstConverter::wordWrap(trim($converter->visitChildren($child, '')), 2);
                 $root .= "\n";
             }
         }
     }
     return $root;
 }
コード例 #7
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)
 {
     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;
 }
コード例 #8
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(' ', ezcDocumentDocbookToRstConverter::$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, ezcDocumentDocbookToRstConverter::escapeRstText($key), ezcDocumentDocbookToRstConverter::escapeRstText($value));
     }
     // Append content, if given
     if ($content !== null) {
         $directive .= "\n" . str_repeat(' ', ezcDocumentDocbookToRstConverter::$indentation + 3) . trim(ezcDocumentDocbookToRstConverter::wordWrap($content, 3)) . "\n";
     }
     // Append an additional newline after the directive contents
     $directive .= "\n";
     return $directive;
 }
コード例 #9
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)
 {
     // Find all anachors in paragraph, create pre paragraph RST anchors out
     // of them and remove them from the paragraph.
     $anchors = $node->getElementsByTagName('anchor');
     $foundAnchors = false;
     foreach ($anchors as $anchor) {
         $root .= '.. _' . $anchor->getAttribute('ID') . ":\n";
         $anchor->parentNode->removeChild($anchor);
         $foundAnchors = true;
     }
     $root .= $foundAnchors ? "\n" : '';
     // Visit paragraph contents
     $contents = $converter->visitChildren($node, '');
     // Remove all line breaks inside the paragraph.
     $contents = trim(preg_replace('(\\s+)', ' ', $contents));
     $root .= ezcDocumentDocbookToRstConverter::wordWrap($contents) . "\n\n";
     $root = $converter->finishParagraph($root);
     return $root;
 }
コード例 #10
0
ファイル: table.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)
 {
     $columns = $this->estimateColumnWidths($converter, $node);
     $rows = $node->getElementsByTagName('row');
     $table = array();
     $rowLines = array();
     $rowNr = 0;
     $oldWidth = $converter->options->wordWrap;
     // Create contents from tables cells recursively and calculate their
     // content width, extending the column width, if necessary.
     foreach ($rows as $row) {
         $cellNr = 0;
         $rowLines[$rowNr] = 1;
         foreach ($row->childNodes as $cell) {
             if ($cell->nodeType === XML_ELEMENT_NODE && $cell->tagName === 'entry') {
                 ezcDocumentDocbookToRstConverter::$wordWrap = $columns[$cellNr];
                 $table[$rowNr][$cellNr] = $cellContent = explode("\n", trim($converter->visitChildren($cell, '')));
                 $rowLines[$rowNr] = max($rowLines[$rowNr], count($cellContent));
                 $columns[$cellNr] = max($columns[$cellNr], $this->getMaxLineLength($cellContent));
                 ++$cellNr;
             }
         }
         ++$rowNr;
     }
     ezcDocumentDocbookToRstConverter::$wordWrap = $converter->options->wordWrap;
     // Build table row seperator
     $separator = '';
     foreach ($columns as $width) {
         $separator .= str_repeat('-', $width) . '  ';
     }
     $separator = rtrim($separator) . "\n";
     // Check if table has a header. RST does only support the foirst row as
     // a header row, so we will only check for this, and render all
     // subsequent header lines as plain contents.
     $hasHeader = (bool) $node->getElementsByTagName('thead')->length;
     // Draw table
     $cellCount = count($columns);
     $root .= str_replace('-', '=', $separator);
     foreach ($table as $rowNr => $row) {
         for ($line = 0; $line < $rowLines[$rowNr]; ++$line) {
             for ($cellNr = 0; $cellNr < $cellCount; ++$cellNr) {
                 $last = $cellNr >= $cellCount - 1;
                 $width = $columns[$cellNr] + ($last ? 0 : 2);
                 $lineContent = isset($table[$rowNr][$cellNr][$line]) ? $table[$rowNr][$cellNr][$line] : '';
                 $root .= $last ? $lineContent . "\n" : str_pad(rtrim($lineContent), $width, ' ');
             }
         }
         // Always add row seperator
         if ($hasHeader && $rowNr === 0 || $rowNr >= count($table) - 1) {
             $root .= str_replace('-', '=', $separator);
         } else {
             $root .= $separator;
         }
     }
     $root .= "\n";
     return $root;
 }
コード例 #11
0
ファイル: convert.php プロジェクト: rdohms/xdebug.org
 function __construct(ezcDocumentDocbookToRstConverterOptions $options = null)
 {
     parent::__construct($options);
     $this->visitorElementHandler['docbook']['ulink'] = new drDocumentDocbookToTextExternalLinkHandler();
     $this->visitorElementHandler['docbook']['link'] = new drDocumentDocbookToTextInternalLinkHandler();
     $this->visitorElementHandler['docbook']['table'] = new drDocumentDocbookToTextTableHandler();
     $this->visitorElementHandler['docbook']['literallayout'] = new drDocumentDocbookToLiteralLayoutHandler();
 }
コード例 #12
0
ファイル: rst.php プロジェクト: axelmdev/ecommerce
 /**
  * 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 ezcDocumentDocbookToRstConverter();
     $converter->options->errorReporting = $this->options->errorReporting;
     $this->contents = $converter->convert($document)->save();
 }
コード例 #13
0
ファイル: docbook_rst.php プロジェクト: jackalope/jr_cr_demo
 /**
  * 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 '';
 }
コード例 #14
0
ファイル: functions.php プロジェクト: Jtgadbois/Pedadida
function fodt2text($filename,$id) {    
    Env::useLibrary('ezcomponents');
    
    $odt = new ezcDocumentOdt();
    $odt->loadFile( $filename );

    $docbook = $odt->getAsDocbook();

    $converter = new ezcDocumentDocbookToRstConverter();
    $rst = $converter->convert( $docbook );
    
    $file_path_txt = 'tmp/fodt2text_' . $id . '.txt';
    file_put_contents( $file_path_txt, $rst );
    $content = file_get_contents($file_path_txt); //Guardamos archivo.txt en $archivo
    unlink($file_path_txt);
    return $content;
}
コード例 #15
0
<?php

require 'tutorial_autoload.php';
$docbook = new ezcDocumentDocbook();
$docbook->loadFile('address.xml');
class myAddressElementHandler extends ezcDocumentDocbookToRstBaseHandler
{
    public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root)
    {
        $root .= $this->renderDirective('address', $node->textContent, array());
        return $root;
    }
}
$converter = new ezcDocumentDocbookToRstConverter();
$converter->setElementHandler('docbook', 'address', new myAddressElementHandler());
$rst = $converter->convert($docbook);
echo $rst->save();
コード例 #16
0
ファイル: rst.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 ezcDocumentDocbookToRstConverter();
     $converter->options->errorReporting = $this->options->errorReporting;
     $this->contents = $converter->convert($document)->save();
 }