public function handle(Document $document) { $this->buttons = new Collection(); // Merge project and document level config $this->config->customMerge($document->attr('buttons', [])); $html = call_user_func([$this, 'handle' . ucfirst($this->config['type']) . 'Type']); $document->setContent($html . $document->getContent()); }
public function handle(Document $document) { /** @var ParserInterface $parser */ $parser = app()->build($this->config['parser']); $parserName = $parser->getName(); $parserConfig = $this->config->get($parserName, []); $parser->setConfig($parserConfig->toArray()); $document->setContent($parser->parse($document->getContent())); }
public function run() { if ($this->canRun()) { $content = $this->document->getContent(); $this->parseArguments(); $arguments = array_merge([$this->isClosing()], $this->arguments); $result = call_user_func_array($this->getCallable(), $arguments); $content = preg_replace('/' . preg_quote($this->raw, '/') . '/', $result, $content, 1); $this->document->setContent($content); } else { throw CodexException::because("Macro [{$this->cleaned}] cannot call because some properties havent been set. Prevent the Macro from running by using the canRun() method."); } }
protected function process(Document $document) { $content = $document->getContent(); $pattern = $this->getTagsPattern(); if (preg_match($pattern, $content, $matches) === 1) { // not really required when using html doc tags. But in case it's frontmatter, it should be removed if ($this->config['remove_tags'] === true) { $content = preg_replace($pattern, '', $content); } $data = Yaml::parse($matches[1]); if (is_array($data)) { $attributes = array_replace_recursive($document->getAttributes(), $data); $document->setAttributes($attributes); } } if ($this->config['remove_tags'] === true) { $document->setContent($content); } return $this; }
public function handle(Document $document) { $content = $document->getContent(); $total = preg_match_all($this->config['regex'], $content, $matches); // create root // for each header // create node // if header nr is same as previous, assign to same parent as previous // if header nr is lower then previous, check parent header nr, if header nr lower then parent nr, check parent, etc // if header nr is higher then previous, assign as previous child // Generate TOC Tree from HTML $prevSize = 0; $prevNode = $rootNode = $this->createHeaderNode(0, 'root'); for ($h = 0; $h < $total; $h++) { $original = $matches[0][$h]; $size = (int) $matches[1][$h]; $text = $matches[2][$h]; if (in_array($size, $this->config['disable'], true)) { continue; } $node = $this->createHeaderNode($size, $text); if ($size === $prevSize) { $prevNode->getParent()->addChild($node); $node->setParent($prevNode->getParent()); } elseif ($size < $prevSize) { $parentNode = $prevNode->getParent(); while (true) { if ($size === $parentNode->getValue()->getSize()) { $parentNode->getParent()->addChild($node); $node->setParent($parentNode->getParent()); break; } if ($parentNode === $rootNode) { break; } $parentNode = $parentNode->getParent(); } } elseif ($size > $prevSize) { $prevNode->addChild($node); $node->setParent($prevNode); } $node->getValue()->setSlug($slug = $this->makeSlug($text)); $link = ''; if ($this->config['header_link_show'] === true) { $link = "<p><a name=\"{$slug}\" class=\"{$this->config['header_link_class']}\"></a></p>"; } $replacement = "{$link}<h{$size}>{$text}</h{$size}>"; $content = str_replace($original, $replacement, $content); $prevSize = $size; $prevNode = $node; } $view = $this->codex->view($this->config['view']); $toc = $this->view->make($view, $this->config)->with('items', $rootNode->getChildren())->render(); $this->addScript(); if (count($this->nodes) >= (int) $this->config['minimum_nodes']) { $document->setContent("<ul class=\"{$this->config['list_class']}\">{$toc}</ul>" . $content); } }
protected function remove(Document $d) { if ($d->attr('title', false) !== false) { $d->setContent(preg_replace($this->config['remove_regex'], '', $d->getContent(), 1)); } }
/** * handle method * * @param \Codex\Documents\Document $document */ public function handle(Document $document) { # $this->markdown->setConfig($settings); $document->setContent($this->markdown->parse($document->getContent())); }