Skip to content

marko/docs-markdown

The canonical Marko documentation content, shipped as an installable Composer package. Every page of the Marko docs lives under this package’s docs/ directory, and MarkdownRepository reads it. This is what makes the documentation modular — the docs are a module like everything else in Marko, so search drivers and the docs site read from one source of truth instead of a copy.

Two consumers read this content:

  1. The search driver (marko/docs-fts) indexes the markdown to power documentation search.
  2. The marko.build Astro site renders it. The site’s content directory (docs/src/content/docs) is a symlink to this package’s docs/ directory, so there is exactly one copy of every page.
Terminal window
composer require marko/docs-markdown

Usually installed automatically as a dependency of a search driver (marko/docs-fts).

Inject MarkdownRepository to read documentation content:

use Marko\DocsMarkdown\MarkdownRepository;
class DocsTool
{
public function __construct(
private MarkdownRepository $repo,
) {}
public function dump(): void
{
foreach ($repo->listAllPages() as $page) {
echo $page; // page id, e.g. "getting-started/installation"
}
$raw = $this->repo->getRawMarkdown('getting-started/installation');
}
}
MethodReturnsDescription
listAllPages()list<string>All page ids (relative paths without extension)
getRawMarkdown(string $id)stringRaw markdown for a page id. Throws DocsMarkdownException if the page is not found or if the resolved path falls outside the docs root (path-traversal attempt).
getDocsPath()stringAbsolute path to the package’s docs/ root

getRawMarkdown() uses realpath containment to verify the resolved file path stays within the docs root before reading. Any page id that resolves outside the root (e.g. ../../etc/passwd) throws DocsMarkdownException::pathTraversal() loudly.