PHPackages                             beholdr/commonmark-shortcode - 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. beholdr/commonmark-shortcode

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

beholdr/commonmark-shortcode
============================

Shortcodes extension for CommonMark

v0.0.4(1mo ago)026↑592.3%MITPHPPHP ^8.4CI passing

Since Apr 7Pushed 2w agoCompare

[ Source](https://github.com/beholdr/commonmark-shortcode)[ Packagist](https://packagist.org/packages/beholdr/commonmark-shortcode)[ Docs](https://github.com/beholdr/commonmark-shortcode)[ GitHub Sponsors](https://github.com/beholdr)[ RSS](/packages/beholdr-commonmark-shortcode/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

CommonmarkShortcode
===================

[](#commonmarkshortcode)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fcbc203c281216ac8f5fa7b895ff849c19ee4d7cd4fd812ca072814e4cc3a5dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265686f6c64722f636f6d6d6f6e6d61726b2d73686f7274636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beholdr/commonmark-shortcode)

[Shortcodes](https://codex.wordpress.org/Shortcode) extension for [CommonMark](https://commonmark.thephpleague.com/).

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

[](#installation)

You can install the package via composer:

```
composer require beholdr/commonmark-shortcode
```

Usage
-----

[](#usage)

```
use Beholdr\CommonmarkShortcode\ShortcodeExtension;
use Beholdr\CommonmarkShortcode\ShortcodeRegistry;
use League\CommonMark\Environment\Environment;
use League\CommonMark\MarkdownConverter;

// create shortcodes registry
$registry = new ShortcodeRegistry();
$registry->register('my-code', fn (array $attrs) => /* Your callback */);

// register extension
$environment = new Environment();
$environment->addExtension(new ShortcodeExtension($registry));

// use it in markdown
$converter = new MarkdownConverter($environment);
echo $converter->convert('Markdown with [my-code]!');
```

You can rebuild a shortcode attribute string using `stringify` helper:

```
use Beholdr\CommonmarkShortcode\ShortcodeAttributes;

$attrs = ['foo' => 'bar', 'enabled' => true];
ShortcodeAttributes::stringify($attrs); // `foo=bar enabled`
```

### Laravel example

[](#laravel-example)

You can use this extension with [graham-campbell/markdown](https://github.com/GrahamCampbell/Laravel-Markdown) or [spatie/laravel-markdown](https://github.com/spatie/laravel-markdown) packages.

For example, you want to replace `[calculator amount=100]` shortcode with Livewire component, passing given attributes.

1. Register extension in the markdown package config:

```
'extensions' => [
    Beholdr\CommonmarkShortcode\ShortcodeExtension::class,
],
```

2. Bind `ShortcodeRegistry` as singleton inside your `AppServiceProvider` and register your shortcodes:

```
use Beholdr\CommonmarkShortcode\ShortcodeAttributes;
use Beholdr\CommonmarkShortcode\ShortcodeRegistry;
use Illuminate\Support\Facades\Blade;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(ShortcodeRegistry::class, fn () => new ShortcodeRegistry);
    }

    public function boot(): void
    {
        app(ShortcodeRegistry::class)
            ->register('calculator', fn ($attrs) =>
                Blade::render(
                    sprintf(
                        '',
                        ShortcodeAttributes::stringify($attrs)
                    )
                )
            );
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Opencode auth
-------------

[](#opencode-auth)

Put `auth.json` into `.devcontainer/mnt` folder and rename it to `opencode-auth.json`.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance95

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.6% 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

Every ~0 days

Total

4

Last Release

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c2acd8f17973138881ff45f60bfa042b6bfa0623af69be06660992aea22c358?d=identicon)[beholdr](/maintainers/beholdr)

---

Top Contributors

[![beholdr](https://avatars.githubusercontent.com/u/741973?v=4)](https://github.com/beholdr "beholdr (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

commonmarkcommonmark-extensionmarkdownshortcodemarkdowncommonmarkshortcodecommonmark-extension

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/beholdr-commonmark-shortcode/health.svg)

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

###  Alternatives

[torchlight/torchlight-commonmark

A Commonmark extension for Torchlight, the syntax highlighting API.

29256.6k6](/packages/torchlight-torchlight-commonmark)[zoon/commonmark-ext-youtube-iframe

Extension for league/commonmark to replace youtube link with iframe

12275.9k1](/packages/zoon-commonmark-ext-youtube-iframe)

PHPackages © 2026

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