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

0.3.0(1y ago)214↓100%MITPHP

Since Mar 23Pushed 1y 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 1mo ago

READMEChangelogDependencies (3)Versions (4)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
```

License
-------

[](#license)

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

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance49

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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

Every ~2 days

Total

3

Last Release

405d ago

### 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 (49 commits)")

###  Code Quality

TestsPHPUnit

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

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[phiki/phiki

Syntax highlighting using TextMate grammars in PHP.

3573.0M23](/packages/phiki-phiki)[spatie/commonmark-highlighter

Highlight your markdown code blocks with league/commonmark

138400.5k19](/packages/spatie-commonmark-highlighter)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[monsieurbiz/sylius-rich-editor-plugin

A Rich Editor plugin for Sylius.

75380.8k6](/packages/monsieurbiz-sylius-rich-editor-plugin)[horstoeko/zugferdvisualizer

A library

33198.3k2](/packages/horstoeko-zugferdvisualizer)

PHPackages © 2026

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