public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $document = $parser->getDocument();
     $document->addHeaderNode(new RawNode('\\title{' . $data . '}'));
     if ($node) {
         $document->addNode($node);
     }
 }
 public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $document = $parser->getDocument();
     $document->addHeaderNode(new RawNode('<title>' . htmlspecialchars($data) . '</title>'));
     if ($node) {
         $document->addNode($node);
     }
 }
 public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $document = $parser->getDocument();
     $document->addCss($data);
     if ($node) {
         $document->addNode($node);
     }
 }
 public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $document = $parser->getDocument();
     if ($node) {
         if ($node instanceof TitleNode) {
             $node->setTarget($data);
         }
         $document->addNode($node);
     }
 }
 public function finalize(Parser $parser)
 {
     foreach ($this->data as &$row) {
         if ($row) {
             foreach ($row as &$col) {
                 $col = $parser->createSpan($col);
             }
         }
     }
 }
Beispiel #6
0
 public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $document = $parser->getDocument();
     foreach ($options as $key => $value) {
         $meta = new MetaNode($key, $value);
         $document->addHeaderNode($meta);
     }
     if ($node) {
         $document->addNode($node);
     }
 }
 public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $environment = $parser->getEnvironment();
     $kernel = $parser->getKernel();
     $files = array();
     foreach (explode("\n", $node->getValue()) as $file) {
         $file = trim($file);
         if ($file) {
             $environment->addDependency($file);
             $files[] = $file;
         }
     }
     $document = $parser->getDocument();
     $document->addNode($kernel->build('Nodes\\TocNode', $files, $environment, $options));
 }
 public function process(Parser $parser, $node, $variable, $data, array $options)
 {
     if ($node) {
         $kernel = $parser->getKernel();
         if ($node instanceof CodeNode) {
             $node->setLanguage(trim($data));
         }
         if ($variable) {
             $environment = $parser->getEnvironment();
             $environment->setVariable($variable, $node);
         } else {
             $document = $parser->getDocument();
             $document->addNode($node);
         }
     }
 }
 /**
  * Process a directive that should parces the next node as a "sub" document
  */
 public final function process(Parser $parser, $node, $variable, $data, array $options)
 {
     $subParser = $parser->getSubParser();
     if ($node instanceof CodeNode) {
         $document = $subParser->parse($node->getValue());
     } else {
         $document = $node;
     }
     $newNode = $this->processSub($parser, $document, $variable, $data, $options);
     if ($newNode) {
         if ($variable) {
             $parser->getEnvironment()->setVariable($variable, $newNode);
         } else {
             $parser->getDocument()->addNode($newNode);
         }
     }
 }
Beispiel #10
0
 public function __construct(Parser $parser, $span)
 {
     if (is_array($span)) {
         $span = implode("\n", $span);
     }
     $tokenId = 0;
     $prefix = mt_rand() . '|' . time();
     $generator = function () use($prefix, &$tokenId) {
         $tokenId++;
         return sha1($prefix . '|' . $tokenId);
     };
     // Replacing literal with tokens
     $tokens = array();
     $span = preg_replace_callback('/``(.+)``/mUsi', function ($match) use(&$tokens, $generator) {
         $id = $generator();
         $tokens[$id] = array('type' => 'literal', 'text' => htmlspecialchars($match[1]));
         return $id;
     }, $span);
     $environment = $parser->getEnvironment();
     $this->environment = $environment;
     // Replacing numbering
     foreach ($environment->getTitleLetters() as $level => $letter) {
         $span = preg_replace_callback('/\\#\\' . $letter . '/mUsi', function ($match) use($environment, $level) {
             return $environment->getNumber($level);
         }, $span);
     }
     // Signaling anonymous names
     $environment->resetAnonymousStack();
     if (preg_match_all('/(([a-z0-9]+)|(`(.+)`))__/mUsi', $span, $matches)) {
         foreach ($matches[2] as $k => $y) {
             $name = $matches[2][$k] ?: $matches[4][$k];
             $environment->pushAnonymous($name);
         }
     }
     // Looking for references to other documents
     $span = preg_replace_callback('/:([a-z0-9]+):`(.+)`/mUsi', function ($match) use(&$environment, $generator, &$tokens) {
         $section = $match[1];
         $url = $match[2];
         $id = $generator();
         $anchor = null;
         $text = null;
         if (preg_match('/^(.+)<(.+)>$/mUsi', $url, $match)) {
             $text = $match[1];
             $url = $match[2];
         }
         if (preg_match('/^(.+)#(.+)$/mUsi', $url, $match)) {
             $url = $match[1];
             $anchor = $match[2];
         }
         $tokens[$id] = array('type' => 'reference', 'section' => $section, 'url' => $url, 'text' => $text, 'anchor' => $anchor);
         $environment->found($section, $url);
         return $id;
     }, $span);
     // Link callback
     $linkCallback = function ($match) use($environment, $generator, &$tokens) {
         $link = $match[2] ?: $match[4];
         $id = $generator();
         $next = $match[5];
         $url = null;
         if (preg_match('/^(.+) <(.+)>$/mUsi', $link, $match)) {
             $link = $match[1];
             $environment->setLink($link, $match[2]);
             $url = $match[2];
         }
         $tokens[$id] = array('type' => 'link', 'link' => $link, 'url' => $url);
         return $id . $next;
     };
     // Replacing anonymous links
     $span = preg_replace_callback('/(([a-z0-9]+)|(`(.+)`))__([^a-z0-9]{1}|$)/mUsi', $linkCallback, $span);
     // Replacing links
     $span = preg_replace_callback('/(([a-z0-9]+)|(`(.+)`))_([^a-z0-9]{1}|$)/mUsi', $linkCallback, $span);
     $this->tokens = $tokens;
     $this->parser = $parser;
     $this->span = $span;
 }
Beispiel #11
0
<?php

include '../../autoload.php';
use reStructuredText\RST\Parser;
use reStructuredText\RST\LaTeX\Kernel;
$parser = new Parser(null, new Kernel());
$document = $parser->parse(file_get_contents('document.rst'));
echo $document->renderDocument();
 /**
  * Helper function, parses a file and returns the document
  * produced by the parser
  */
 private function parse($file)
 {
     $directory = __DIR__ . '/html/';
     $parser = new Parser();
     $environment = $parser->getEnvironment();
     $environment->setCurrentDirectory($directory);
     return $parser->parseFile($directory . $file);
 }
Beispiel #13
0
 public function processAction(Parser $parser, $variabe, $data, array $options)
 {
     $environment = $parser->getEnvironment();
     $environment->setUrl(trim($data));
 }
 /**
  * Helper function, parses a file and returns the document
  * produced by the parser
  */
 private function parse($file)
 {
     $directory = __DIR__ . '/files/';
     $parser = new Parser();
     $environment = $parser->getEnvironment();
     $environment->setCurrentDirectory($directory);
     $data = file_get_contents($directory . $file);
     return $parser->parse($data);
 }
 public function processNode(Parser $parser, $variable, $data, array $options)
 {
     return $parser->createSpan($data);
 }
Beispiel #16
0
 public function processNode(Parser $parser, $variable, $data, array $options)
 {
     $environment = $parser->getEnvironment();
     $url = $environment->relativeUrl($data);
     return new ImageNode($url, $options);
 }