PHPackages                             zhenhaihou/commonmark-highlighter - 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. zhenhaihou/commonmark-highlighter

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

zhenhaihou/commonmark-highlighter
=================================

Highlight your markdown code blocks with 升级league/commonmark版本，添加表格，删除线的转换

v3.0.1(6y ago)08MITPHPPHP ^7.2

Since Nov 28Pushed 6y agoCompare

[ Source](https://github.com/zhenhaihou/commonmark-highlighter)[ Packagist](https://packagist.org/packages/zhenhaihou/commonmark-highlighter)[ Docs](https://github.com/zhenhaihou/commonmark-highlighter)[ RSS](/packages/zhenhaihou-commonmark-highlighter/feed)WikiDiscussions master Synced today

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

Highlight your markdown code blocks with league/commonmark
==========================================================

[](#highlight-your-markdown-code-blocks-with-leaguecommonmark)

[![Latest Version](https://camo.githubusercontent.com/9fc7df1ce11fd45079935195a512b5c5306900d6c8038f8739e755c3bbc95368/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7370617469652f636f6d6d6f6e6d61726b2d686967686c6967687465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/spatie/commonmark-highlighter/releases)[![Build Status](https://camo.githubusercontent.com/494968ad5725933b200de819143b174a6fa264cf40d811e559256f5bb2188b7e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f636f6d6d6f6e6d61726b2d686967686c6967687465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/commonmark-highlighter)[![Quality Score](https://camo.githubusercontent.com/e060b5d79c400fa573f4f31f50c40f618f978d593bff7e5c8c0568bbf32cb4d2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f636f6d6d6f6e6d61726b2d686967686c6967687465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/commonmark-highlighter)[![StyleCI](https://camo.githubusercontent.com/7b009cb8b2015ede08d0d4971475c2166cfc23d3f453da9c3bdb04cf43a3c6ed/68747470733a2f2f7374796c6563692e696f2f7265706f732f3135393531333331302f736869656c64)](https://styleci.io/repos/159513310)[![Total Downloads](https://camo.githubusercontent.com/d7df5975a0c5a0100caf191af69ab2d1b38ef9fefc665ad0f637cbbfcba458d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f636f6d6d6f6e6d61726b2d686967686c6967687465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/commonmark-highlighter)

A block renderer for [league/commonmark](https://github.com/thephpleague/commonmark) to highlight code blocks using [scrivo/highlight.php](https://github.com/scrivo/highlight.php).

> highlight.php is a server side code highlighter written in PHP that currently supports 185 languages. It's a port of highlight.js by Ivan Sagalaev that makes full use of the language and style definitions of the original JavaScript project.

The output html is compatible with highlight.js themes, which you can explore on [highlightjs.org](https://highlightjs.org/static/demo/).

What are the benefits of using this package over highlight.js?

- Less JavaScript, which means faster page loads
- No more flash of unstyled code blocks

This project was inspired by [sixlive/parsedown-highlight](https://github.com/sixlive/parsedown-highlight).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/commonmark-highlighter
```

Usage
-----

[](#usage)

Create a custom CommonMark environment, and register the `FencedCodeRenderer` and `IndentedCodeRender` as described in the [league/commonmark documentation](https://commonmark.thephpleague.com/customization/block-rendering/).

```
use League\CommonMark\Block\Element\FencedCode;
use League\CommonMark\Block\Element\IndentedCode;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;

$environment = Environment::createCommonMarkEnvironment();
$environment->addBlockRenderer(FencedCode::class, new FencedCodeRenderer());
$environment->addBlockRenderer(IndentedCode::class, new IndentedCodeRenderer());

$commonMarkConverter = new CommonMarkConverter([], $environment);

echo $commonMarkConverter->convertToHtml($markdown);
```

The underlying highlight library recommends specifying a subset of languages for the auto-detection. You can pass an array of languages to any of the renderers.

```
new FencedCodeRenderer(['html', 'php', 'js']);

new IndentedCodeCodeRenderer(['html', 'php', 'js']);
```

### Highlighting specific lines

[](#highlighting-specific-lines)

Line numbers start at 1.

```php - Don't highlight any lines
```php{4} - Highlight just line 4
```php{4-6} - Highlight the range of lines from 4 to 6 (inclusive)
```php{1,5} - Highlight just lines 1 and 5 on their own
```php{1-3,5} - Highlight 1 through 3 and then 5 on its own
```php{5,7,2-3} - The order of lines don't matter
However, specifying 3-2 will not work.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

Support us
----------

[](#support-us)

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/spatie). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 52.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 ~47 days

Recently: every ~69 days

Total

11

Last Release

2297d ago

Major Versions

0.1.0 → 1.0.02018-11-30

1.1.0 → 2.0.02019-07-05

2.1.0 → 3.0.02020-03-19

PHP version history (2 changes)0.1.0PHP ^7.1

1.0.3PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/23db69409a930456799d8abaca7b3ca37353f8a270fdab97942e8bc3e7ae6510?d=identicon)[zhenhaihou](/maintainers/zhenhaihou)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (21 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (6 commits)")[![allejo](https://avatars.githubusercontent.com/u/1246453?v=4)](https://github.com/allejo "allejo (3 commits)")[![imliam](https://avatars.githubusercontent.com/u/4326337?v=4)](https://github.com/imliam "imliam (3 commits)")[![zhenhaihou](https://avatars.githubusercontent.com/u/9348367?v=4)](https://github.com/zhenhaihou "zhenhaihou (3 commits)")[![rubenvanassche](https://avatars.githubusercontent.com/u/619804?v=4)](https://github.com/rubenvanassche "rubenvanassche (2 commits)")[![boast](https://avatars.githubusercontent.com/u/51127?v=4)](https://github.com/boast "boast (1 commits)")[![jonnybarnes](https://avatars.githubusercontent.com/u/108303?v=4)](https://github.com/jonnybarnes "jonnybarnes (1 commits)")

---

Tags

commonmark-highlighterzhenhaihou

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zhenhaihou-commonmark-highlighter/health.svg)

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

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

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

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[contao/core-bundle

Contao Open Source CMS

1231.6M2.8k](/packages/contao-core-bundle)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[roundcube/roundcubemail

The Roundcube Webmail suite

7.1k2.4k3](/packages/roundcube-roundcubemail)[phlak/directory-lister

PHP directory lister

2.5k1.4k](/packages/phlak-directory-lister)

PHPackages © 2026

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