PHPackages                             mistralys/markdown-renderer - 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. mistralys/markdown-renderer

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

mistralys/markdown-renderer
===========================

CommonMark Markdown renderer for PHP with pre- and post-processors.

1.0.3(1y ago)125MITPHP

Since Aug 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Mistralys/markdown-renderer)[ Packagist](https://packagist.org/packages/mistralys/markdown-renderer)[ RSS](/packages/mistralys-markdown-renderer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

Markdown Renderer
=================

[](#markdown-renderer)

CommonMark Markdown renderer for PHP with the capability to define pre- and post-processors with custom syntax.

Usage
-----

[](#usage)

### From a Markdown string

[](#from-a-markdown-string)

```
use Mistralys\Markdown\MarkdownRenderer;

$markdown = render();
```

### Adding a processor

[](#adding-a-processor)

Any number of processors can be added with the `addProcessor()`method. They are executed in the order that they are added.

Example: Adding the bundled video processor.

```
use Mistralys\Markdown\MarkdownRenderer;
use Mistralys\MarkdownRenderer\Processors\Bundled\VideosProcessor;

$file = FileInfo::factory('/path/to/markdown.md');

echo Renderer::factory($file)
    ->addProcessor(new VideosProcessor($renderer))
    ->render();
```

Bundled commands
----------------

[](#bundled-commands)

Several commands are bundled with the library, provided by the processor classes located at:

[Processors/Bundled](/src/MarkdownRenderer/Processors/Bundled)

### Displaying images

[](#displaying-images)

#### Configuration

[](#configuration)

```
use Mistralys\MarkdownRenderer\Processors\Bundled\ImagesProcessor;

$processor = new ImagesProcessor($renderer);

// The base URL is prepended to all image paths.
$processor->setImageBaseURL('/img/');
```

#### Syntax

[](#syntax)

It uses the following syntax for images:

```
{image: "test.jpg"
    id="imageID"
    width="150px"
    height="150px
    class="classA classB"
    alt="Alternative text"
    title="Tooltip title"
}

```

The image path is mandatory, all other attributes are optional. If no alternative text is provided, the title is used. If both1 are empty, an empty `alt=""` attribute is used.

Nested double quotes must be escaped like this:

```
title="Something \"here\""

```

> NOTE: Attributes are not passed through as-is. Only attributes known by the processor are used, so any additional attributes are ignored.

Adding custom commands
----------------------

[](#adding-custom-commands)

The library is based on a simple syntax for defining custom commands, which follow the following scheme with pseudo HTML attributes:

```
{commandName: "value" name="named value" property}

```

The parsing of these commands is handled automatically by the library, and the attributes can easily be accessed via a helper class when rendering the matching content.

### Adding a custom processor

[](#adding-a-custom-processor)

If you want to do your own syntax parsing, create a class based on `BaseProcessor`. Use the `BaseCommandBasedProcessor` class if you want to use the library's command syntax (easiest to implement). Simply implement all abstract methods, and you're good to go.

> Every abstract method has documentation on what you are supposed to do.

You can create your processor class anywhere in your project, and add it to the renderer with the `addProcessor()` method.

```
use Mistralys\Markdown\MarkdownRenderer;
use My\Custom\CommandProcessor;

$file = FileInfo::factory('/path/to/markdown.md');

echo Renderer::factory($file)
    ->addProcessor(new CommandProcessor($renderer))
    ->render();
```

Origin
------

[](#origin)

I had created similar Markdown filters in several of my personal and professional projects. Each project had different enough requirements for syntax and content, and were easy enough to implement, so for a long time I did not take the step to move the common functionality to a separate library.

Another recent project made me take the step. As is often the case, I was annoyed enough by having to create regexes to parse the commands that I decided to do it right.

Philosophy
----------

[](#philosophy)

I have read quite a few discussions on what kind of information should be included in a Markdown file. Image widths are one thing that the community is divided on. I agree that the width of an image is layout information, not content. The requirement is real, however, and appears often enough for me to take a pragmatic approach.

My philosophy is that as long as the Markdown content stays easily readable, and that the added syntax does not interfere with reading the document, I don't mind.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance46

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Every ~78 days

Total

4

Last Release

416d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8895528?v=4)[Mistralys](/maintainers/Mistralys)[@Mistralys](https://github.com/Mistralys)

---

Top Contributors

[![Mistralys](https://avatars.githubusercontent.com/u/8895528?v=4)](https://github.com/Mistralys "Mistralys (38 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mistralys-markdown-renderer/health.svg)

```
[![Health](https://phpackages.com/badges/mistralys-markdown-renderer/health.svg)](https://phpackages.com/packages/mistralys-markdown-renderer)
```

###  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)[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)[torchlight/engine

The PHP-based Torchlight code annotation and rendering engine.

655.7k4](/packages/torchlight-engine)

PHPackages © 2026

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