alto / commonmark-include
CommonMark extension that includes and re-parses external Markdown files at @include directives.
Fund package maintenance!
v1.0.0
2026-07-30 02:00 UTC
Requires
- php: ^8.3
- league/commonmark: ^2.7
README
Summary
The backbone of large documentation sets. @include directives pull in external markdown fragments and fully parse them inline -- making one-file-per-section composition possible without a build system. Supports optional line-range selection for embedding partial files, with circular-include protection to keep deeply nested setups safe.
Installation
composer require
composer require alto/commonmark
Registration
use Alto\CommonMark\Extension\Include\IncludeExtension; use League\CommonMark\Environment\Environment; $environment = new Environment(); $environment->addExtension(new IncludeExtension(__DIR__ . '/docs'));
Usage
@include "sections/intro.md" @include "sections/features.md" {lines: 5-20}
Configuration
- Constructor:
new IncludeExtension(string $basePath='.', int $maxDepth=10, array $allowedExtensions=['md','markdown'], int $maxFileSize=1048576). - Validates extension, file size, and readable path constraints.
Minimal Example
# Guide @include "parts/overview.md" @include "parts/setup.md"
Development
This extension is actively developed in the alto/commonmark monorepo.
License
MIT License -- Simon André & Alto