PHPackages                             alto/commonmark-import - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. alto/commonmark-import

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

alto/commonmark-import
======================

CommonMark extension that embeds raw file content at @import directives, with line range, language, and indent options.

v1.0.0(yesterday)00MITPHPPHP ^8.3

Since Jul 30Pushed yesterdayCompare

[ Source](https://github.com/altophp/commonmark-import)[ Packagist](https://packagist.org/packages/alto/commonmark-import)[ Docs](https://github.com/altophp/commonmark)[ GitHub Sponsors](https://github.com/sponsors/smnandre)[ RSS](/packages/alto-commonmark-import/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

Import Extension
================

[](#import-extension)

Summary
-------

[](#summary)

Solves the copy-paste drift problem between documentation and source code. `@import` directives pull external file content directly into fenced code blocks at parse time -- with optional line-range selection, language hinting, and indentation control. Your code samples stay in sync with the actual source by definition, not by discipline.

Installation
------------

[](#installation)

### composer require

[](#composer-require)

```
composer require alto/commonmark
```

### Registration

[](#registration)

```
use Alto\CommonMark\Extension\Import\ImportExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment();
$environment->addExtension(new ImportExtension(__DIR__ . '/docs'));
```

Usage
-----

[](#usage)

```
@import "path/to/file.md"
@import "src/Handler.php" {lines: 10-40, lang: php, indent: 2}
```

Configuration
-------------

[](#configuration)

- Constructor: `new ImportExtension(string $basePath = '.', int $maxDepth = 10)`.
- Guards against circular imports and excessive nesting depth.

Minimal Example
---------------

[](#minimal-example)

```
# API

@import "snippets/auth.md"
@import "src/Auth.php" {lines: 1-30, lang: php}
```

Development
-----------

[](#development)

This extension is actively developed in the [`alto/commonmark`](https://github.com/altophp/commonmark) monorepo.

- [Report a bug](https://github.com/altophp/commonmark/issues/new?labels=bug)
- [Suggest a feature](https://github.com/altophp/commonmark/issues/new?labels=enhancement)
- [Open a Pull Request](https://github.com/altophp/commonmark/pulls)

License
-------

[](#license)

MIT License -- [Simon André](https://smnandre.dev) &amp; [Alto](https://github.com/altophp)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (3 commits)")

---

Tags

altocode-embedcommonmarkcommonmark-extensionfile-embedimportmarkdownphpsnippetphpmarkdownimportcommonmarksnippetaltocommonmark-extensionfile-embedcode-embed

### Embed Badge

![Health badge](/badges/alto-commonmark-import/health.svg)

```
[![Health](https://phpackages.com/badges/alto-commonmark-import/health.svg)](https://phpackages.com/packages/alto-commonmark-import)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.5k10](/packages/helsingborg-stad-municipio)[petebishwhip/laradocs

Maintain beautiful, version-controlled documentation alongside your Laravel codebase. Markdown in, a polished docs site out.

1067.0k](/packages/petebishwhip-laradocs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
