alto/commonmark-include

CommonMark extension that includes and re-parses external Markdown files at @include directives.

Maintainers

Package info

github.com/altophp/commonmark-include

Homepage

Issues

Documentation

pkg:composer/alto/commonmark-include

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-07-30 02:00 UTC

This package is auto-updated.

Last update: 2026-07-30 02:56:20 UTC


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