PHPackages                             alto/commonmark-source - 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-source

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

alto/commonmark-source
======================

CommonMark extension that displays source files as highlighted code blocks at @source directives, with title, line numbers, and highlighting.

v1.0.0(yesterday)00MITPHPPHP ^8.3

Since Jul 30Pushed yesterdayCompare

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

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

Source Extension
================

[](#source-extension)

Summary
-------

[](#summary)

The flagship of the set. `@source` directives embed a real file -- not a copy -- into your documentation at parse time, with automatic syntax class detection, precise line-range selection, optional line numbers, and per-line highlighting. Your docs and your source stay in sync by construction.

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

[](#installation)

### composer require

[](#composer-require)

```
composer require alto/commonmark
```

### Registration

[](#registration)

```
use Alto\CommonMark\Extension\Source\SourceExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment();
$environment->addExtension(new SourceExtension(__DIR__));
```

Usage
-----

[](#usage)

```
@source "src/Service.php"
@source "src/Service.php" {lines: 10-30, numbers: true, highlight: "14,18-20"}
```

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

[](#configuration)

- Constructor: `new SourceExtension(string $basePath='.', array $allowedExtensions=[], bool $escapeHtml=true, int $maxFileSize=1048576)`.
- Supports extension allowlists and max-size protections.

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

[](#minimal-example)

```
# Service excerpt

@source "src/Service.php" {lines: 1-25, numbers: true}
```

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-blockcommonmarkcommonmark-extensionmarkdownphpsourcesource-codesyntax-highlightphpmarkdowncommonmarksourcealtocommonmark-extensionsource-codesyntax-highlightcode-block

### Embed Badge

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

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

###  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)
