PHPackages                             semmelsamu/commonmark-extensions - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. semmelsamu/commonmark-extensions

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

semmelsamu/commonmark-extensions
================================

Custom Markdown extensions for CommonMark PHP

1.0.1(1mo ago)21141MITPHPCI passing

Since Mar 23Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/semmelsamu/commonmark-extensions)[ Packagist](https://packagist.org/packages/semmelsamu/commonmark-extensions)[ RSS](/packages/semmelsamu-commonmark-extensions/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (0)

CommonMark Extensions
=====================

[](#commonmark-extensions)

Custom extensions for the [CommonMark PHP](https://commonmark.thephpleague.com/) Markdown parser. Extensions contained:

- **Callout** - Renders obsidian-like callout and github-like alarm blockquotes
- **CodeHighlighting** - Highlights code blocks using [highlight.php](https://github.com/scrivo/highlight.php)
- **LaTex** - Escapes inline- and block-level latex code between dollar signs (`$`)
- **Wikilink** - Processes Wikilinks like in Obsidian
- **WikilinkEmbed** - Embeds Wikilinks prefixed with a `!`

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

[](#installation)

You can install this package with [Composer](https://getcomposer.org/) (recommended):

```
composer require semmelsamu/commonmark-extensions
```

Alternatively (not recommended), refer to the latest stable [release](https://github.com/semmelsamu/commonmark-extensions/releases) and download the source code manually.

Setup
-----

[](#setup)

```
use League\CommonMark\Environment\Environment;

// Create the converter environment:
$environment = new Environment($config);

// Add the extensions you wish:
$environment->addExtension(new CommonmarkExtension());

// Go forth and convert you some Markdown!
$converter = new MarkdownConverter($environment);
```

Usage
-----

[](#usage)

### Callout

[](#callout)

```
use Semmelsamu\CommonmarkExtensions\Callout\CalloutExtension;
```

You may want to configure the extension:

```
$config = [
    "callout" => [
        "render_icon" => fn(string) => string;
    ],
    // other configuration ...
]
```

- `render_icon` - A closure expecting the callout type and returning valid HTML which will be rendered as the icon of the callout.

### CodeHighlighting

[](#codehighlighting)

```
use Semmelsamu\CommonmarkExtensions\CodeHighlighting\CodeHighlightingExtension;
```

You may want to download one of the various [highlight.js themes](https://highlightjs.org/examples) in order to actually see any code highlighting, as **this extension does not apply any colors to the code by itself, it only applies CSS classes**. Download the css files [here](https://github.com/highlightjs/highlight.js/tree/main/src/styles) and load them in your HTML.

### LaTex

[](#latex)

```
use Semmelsamu\CommonmarkExtensions\LaTex\LaTexExtension;
```

You may want to download a LaTex highlighting engine like [MathJax](https://www.mathjax.org/), as **this extension does not render LaTex, but escapes it**. Use the code below to load MathJax into your HTML:

```

    MathJax = {
        tex: {
            inlineMath: [
                ["$", "$"],
                ["\\(", "\\)"],
            ],
            displayMath: [["$$", "$$"]],
        },
        options: {
            enableMenu: false,
        },
    };

```

### Wikilink

[](#wikilink)

```
use Semmelsamu\CommonmarkExtensions\Wikilink\WikilinkExtension;
```

You may want to configure the extension:

```
$config = [
    'wikilink' => [
        'resolve' => fn (string) => string
    ],
    [
    'slug_normalizer' => [
        'unique' => false,
    ]
]
```

- `resolve` - A closure expecting the wikilink text and returning the resolved href value which will be used in the `` tag.
- If using the [Heading Permalink Extension](https://commonmark.thephpleague.com/2.6/extensions/heading-permalinks/), you want to set the `slug_normalizer` option `unique` to `false`, as else the Wikilink anchors will not link correctly to their respective headings.

### WikilinkEmbed

[](#wikilinkembed)

```
use Semmelsamu\CommonmarkExtensions\WikilinkEmbed\WikilinkEmbedExtension;
```

You may want to configure the extension:

```
$config = [
    'wikilink_embed' => [
        'resolve' => fn(string) => string
    ]
];
```

- `resolve` - A closure expecting the wikilink text and returning the resolved href value which will be used in the `` tag.

As a fallback, this extension already provides a basic iframe renderer for Embeds. You may add your own renderers with higher priority to extend this functionality. The example below shows an image renderer, so that images can also be written as wikilinks:

```
/**
 * Don't forget to also add this renderer to your environment:
 * `$environment->addRenderer(new WikilinkEmbedImageRenderer())`
 */
class WikilinkEmbedImageRenderer implements NodeRendererInterface
{
    public function render(Node $node, ChildNodeRendererInterface $childRenderer)
    {
        Embed::assertInstanceOf($node);

        if (!preg_match('/\.(jpg|jpeg|png|gif)$/i', $src)) {
            // Not an image, let this embed be handled by some other renderer
            return null;
        }

        $attributes = ['href' => $node->src];

        if ($node->caption) {
            $attributes['alt'] = $node->caption;
        }

        return new HtmlElement(
            'image',
            $attributes
        );
    }
}
```

Testing
-------

[](#testing)

```
./vendor/bin/phpunit --do-not-cache-result
```

Formatting
----------

[](#formatting)

This Project uses [Laravel Pint](https://laravel.com/docs/13.x/pint):

```
./vendor/bin/pint
```

License
-------

[](#license)

This project is licenced under the MIT license. See the [`LICENSE`](LICENSE) file for more information.

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance90

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.5% 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 ~101 days

Total

5

Last Release

51d ago

Major Versions

0.3.0 → 1.0.02026-04-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/96a3fd7a8f30de5eafd3d754219edcab8e21d50af00ee08bea389cdf82b3f38d?d=identicon)[semmelsamu](/maintainers/semmelsamu)

---

Top Contributors

[![semmelsamu](https://avatars.githubusercontent.com/u/57997725?v=4)](https://github.com/semmelsamu "semmelsamu (66 commits)")[![DavidOliver](https://avatars.githubusercontent.com/u/192853?v=4)](https://github.com/DavidOliver "DavidOliver (1 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/semmelsamu-commonmark-extensions/health.svg)

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

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.3k10](/packages/helsingborg-stad-municipio)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.8k69.4k](/packages/grumpydictator-firefly-iii)[roundcube/roundcubemail

The Roundcube Webmail suite

7.0k1.4k3](/packages/roundcube-roundcubemail)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[phiki/phiki

Syntax highlighting using TextMate grammars in PHP.

3673.5M48](/packages/phiki-phiki)[contao/core-bundle

Contao Open Source CMS

1231.6M2.6k](/packages/contao-core-bundle)

PHPackages © 2026

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