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); } } }
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; }
/** * 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); }
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) { $environment = $parser->getEnvironment(); $url = $environment->relativeUrl($data); return new ImageNode($url, $options); }