/** * @param \nochso\WriteMe\Placeholder\Call $call * @param string $templateName 'summary', 'short' or 'full' */ public function api(Call $call, $templateName) { $classes = $this->getClasses($call->getDocument()); $template = new Template(); $template->prepare($classes, $call->getDocument()->getFrontmatter()); $call->replace($template->render($templateName . '.php')); }
/** * @param \nochso\WriteMe\Placeholder\Call $call * @param string $imageUrl URL to a badge image. * @param string $altText Alternative text for image. * @param string|null $url Optional URL the image will link to. If null, no link will * be created. */ public function image(Call $call, $imageUrl, $altText, $url = null) { $badge = sprintf('![%s](%s)', $altText, $imageUrl); if ($url !== null) { $badge = sprintf('[%s](%s)', $badge, $url); } $call->replace($badge); }
public function wildcard(Call $call) { $path = $call->getIdentifier(); if ($call->getMethod() !== null) { $path .= '.' . $call->getMethod(); } $value = $call->getDocument()->getFrontmatter()->get($path); if ($value !== null) { $call->replace($value); } }
public function writemePlaceholderDocs(Call $call) { $classes = []; foreach ($this->placeholders->toArray() as $placeholder) { $classes[get_class($placeholder)] = ReflectionClass::createFromInstance($placeholder); } $template = new TemplateData(); $template->setHeaderStartLevel($this->options->getValue('placeholder-docs.header-depth')); $template->prepare($classes, $this->placeholders); $docs = $template->render('full.php'); $docs = (new Converter())->escape($docs); $call->replace($docs); }
/** * `@toc.sub@` collects Markdown headers that are **below** the placeholder and on the same or deeper level. * If there's a header above the placeholder, its depth will be used as a minimum depth. * If there's no header above the placeholder, the first header after the placeholder will be used for the minimum depth. * There is currently no maximum depth for `@toc.sub@`. * * e.g. * ```markdown * # ignore me * * @toc.sub@ * ## sub 1 * # ignore me again * ``` * is converted into * * ```markdown * # ignore me * - [sub 1](#sub-1) * ## sub 1 * # ignore me again * ``` * * @param \nochso\WriteMe\Placeholder\Call $call * @param int $maxDepth How many levels of headers you'd like to keep. * Defaults to zero, meaning all sub-headers are kept. */ public function tocSub(Call $call, $maxDepth = 0) { $parser = new Markdown\HeaderParser(); $headerList = $parser->extractHeaders($call->getDocument()); $lines = Multiline::create($call->getDocument()->getContent()); $lineIndex = $lines->getLineIndexByCharacterPosition($call->getStartPositionOfRawCall()); $headers = $headerList->getHeadersBelowLine($lineIndex); if ($maxDepth > 0) { $minDepth = $this->getMinimumDepth($headers); // Filter headers that are relatively too deep $headers = array_filter($headers, function (Markdown\Header $header) use($minDepth, $maxDepth) { return $header->getLevel() - $minDepth < $maxDepth; }); } $toc = $this->formatTOC($headers); $call->replace($toc); }