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 static function processorNotFound($msg = '', Document $document = null) { $msg = '[Processor Not Found] ' . $msg; if ($document) { $msg .= " for project: [{$document->getProject()->getName()}]"; } return new static($msg); }
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); } }
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())); }
/** * @{inheritDoc} */ public function collect() { $this->codex = $codex = codex(); $project = $codex->projects->getActive(); return ['version' => $codex->getVersion(), 'project' => $project ? $project->getName() : '', 'ref' => $project ? $project->getRef() : '', 'document' => $this->document ? $this->document->getPath() : '', 'data' => $this->data->transform(function ($item) { if (!is_string($item)) { $item = $this->getDataFormatter()->formatVar($item); } return $item; })->toArray()]; }
public function handle(Document $document) { $this->theme = $this->codex->theme; $this->addBaseAssets(); foreach ($this->config['plugins'] as $plugin) { $this->addPlugin($plugin); } return; $dom = $document->getDom(); $dom->find('//pre/code')->each(function (Element $el) { $cls = $el->getAttribute('class'); $a = 'a'; }); }
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 run($name, Document $document) { /** @var Processor $annotation */ $this->currentDocument = $document; $project = $document->getProject(); $processor = $this->get($name); if ($processor->plugin && false === $this->addons->plugins->canRunPlugin($processor->plugin)) { throw CodexException::because("Cannot run processor [{$name}] belonging to plugin [{$processor->plugin}] because the plugin can not run. Ensure the plugin is installed and enabled"); } // hook point before can prevent the processor from running if (false === $this->hookPoint('addons:processor:before', [$name])) { return $processor; } $instance = $this->getInstance($name); $annotation = $processor['annotation']; if ($annotation->config !== false) { // get default config if (!property_exists($instance, $annotation->config)) { throw CodexException::because('Config not found for ' . $processor['class']); } $config = $instance->{$annotation->config}; $config = array_replace_recursive($config, $project->config('processors.' . $name, []), $document->attr('processors.' . $name, [])); $instance->{$annotation->config} = new Collection($config); } if (property_exists($instance, 'codex')) { $instance->codex = $document->getCodex(); } if (property_exists($instance, 'project')) { $instance->project = $document->getProject(); } if (property_exists($instance, 'document')) { $instance->document = $document; } // hook point after can prevent the processor from running if (false === $this->hookPoint('addons:processor:after', [$name, $annotation, $instance])) { return $processor; } $this->app->call([$instance, $annotation->method], compact('document')); return $processor; }
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."); } }
/** * This will get the configured macros. It merges (if defined) the global config, project config and document attributes. * * Project macros will overide global macros with the same name. * Document macros will overide project macros with the same name. * Other then that, everything will be merged/inherited. * * @return array The collected macros as id(used for regex) > handler(the class string name with @ method callsign) */ protected function getAllMacroDefinitions() { $tags = $this->codex->config('processors.macros', []); $tags = array_merge($tags, $this->project->config('processors.macros', [])); return array_merge($tags, $this->document->attr('processors.macros', [])); }
/** * @{inheritDoc} */ public function getWidgets() { $applied = $this->document->getProcessed(); return ['codex' => ['icon' => 'lock', 'widget' => 'PhpDebugBar.Widgets.CodexWidget', 'map' => 'codex', 'default' => '{}'], 'codex-document' => ['icon' => 'file-text', 'tooltip' => 'Document Name', 'map' => 'codex.Document Name', 'default' => ''], 'codex-project-version' => ['icon' => 'code-fork', 'tooltip' => 'Codex Project Version', 'map' => 'codex.Project Version', 'default' => ''], 'codex-project' => ['icon' => 'book', 'tooltip' => $this->format('Codex Project \\n Filters: ' . $applied->implode(', ')), 'map' => 'codex.Project Name', 'default' => '']]; }
public function getLinkActions() { $definitions = $this->codex->config('processors.links', []); $definitions = array_merge($definitions, $this->config['links']); return array_merge($definitions, $this->document->attr('processors.links', [])); }
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())); }
public function printValue($isCloser = false, $key, $default = null) { return $this->document->attr($key, $default); }