PHPackages                             varspool/pygments-bundle - 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. varspool/pygments-bundle

ActiveSymfony-bundle[Parsing &amp; Serialization](/categories/parsing)

varspool/pygments-bundle
========================

A bundle that integrates Pygments to provide code-highlighting within Sundown rendered Markdown

1.0.0(11y ago)98563MITPHP

Since Sep 25Pushed 11y ago1 watchersCompare

[ Source](https://github.com/varspool/PygmentsBundle)[ Packagist](https://packagist.org/packages/varspool/pygments-bundle)[ RSS](/packages/varspool-pygments-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

VarspoolPygmentsBundle
======================

[](#varspoolpygmentsbundle)

Provides (X)HTML rendering of Markdown similar to GFM (Github flavored markdown), including syntax-highted fenced code blocks. Code coloring is provided by the Python Pygments library (interfaces with pygmentize using proc\_open for now).

VarspoolPygmentsBundle doesn't reinvent the wheel: it uses the Sundown support in [KwattroMarkdownBundle](https://github.com/kwattro/KwattroMarkdownBundle) to do the initial Markdown rendering.

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

[](#installation)

### Install the Sundown PHP extension

[](#install-the-sundown-php-extension)

The [Sundown extension](http://pecl.php.net/package/sundown) is available via PECL in beta state, so installing it should be something like:

```
sudo pecl install sundown-beta
```

You'll be able to tell you're successful when the Sundown extension is shown in the output of `php\_info()`:

```
php -i | grep 'Sundown Support'
```

### Install pygments

[](#install-pygments)

This is usually available via your package manager, as the `python-pygments`package or similar.

```
sudo apt-get install python-pygments
```

The key thing, however, is just that you have the pygmentize script available to execute. It's usually at `/usr/bin/pygmentize`, but if not, you can configure its location (see app/config.yml below).

### Composer

[](#composer)

Add `varspool/pygments-bundle` to your requires field. Then install/update your dependencies.

### app/AppKernel.php

[](#appappkernelphp)

Register the `KwattroMarkdownBundle` and `VarspoolPygmentsBundle`:

```
# app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        //...
        new Kwattro\MarkdownBundle\KwattroMarkdownBundle(),
        new Varspool\PygmentsBundle\VarspoolPygmentsBundle(),
    );
}
```

### app/config.yml

[](#appconfigyml)

Next, configure the default Markdown renderer for the `kwattro_markdown` service, so that it'll stop complaining.

```
kwattro_markdown:
    renderer:     xhtml
```

You can optionally configure where to find the `pygmentize` script. The default is `/usr/bin/pygmentize`:

```
varspool_pygments:
    bin:     /usr/local/bin/pygmentize
```

You can also specify lexer arguments, that'll be passed to Pygmentize. See [the documentation](http://pygments.org/docs/lexers/) for a list:

```
varspool_pygments:
  lexer_arguments:
    linenos: table
```

Despite its name, this option can also contain [formatter arguments](http://pygments.org/docs/formatters/), such as linenos.

Usage
-----

[](#usage)

### Services

[](#services)

#### kwattro\_markdown

[](#kwattro_markdown)

KwattroMarkdownBundle usually provides the `kwattro_markdown` service. This won't change when you set up VarspoolPygmentsBundle: the service will continue to provide a Markdown rendering without syntax highlighting. This service is usually a `Kwattro\MarkdownBundle\Markdown\KwattroMarkdown` object.

```
$xhtml = $this->get('kwattro_markdown')->render($markdown_source);
```

#### varspool\_markdown

[](#varspool_markdown)

Once you've installed VarspoolPygmentsBundle, you'll have a second service available: `vaspool_markdown`. This service will extend `Kwattro\MarkdownBundle\Markdown\KwattroMarkdown`, so you should just be able to swap it in as a replacement quite easily. It'll colorize fenced code blocks in the markdown. This service is usually a `Varspool\PygmentsBundle\Markdown\KwattroMarkdown` object.

```
$colorized_xhtml = $this->get('varspool_markdown')->render($markdown_source);
```

#### varspool\_pygments

[](#varspool_pygments)

This service is the Sundown renderer instance responsible for coloring the output. It's usually an instance of `Varspool\PygmentsBundle\Sundown\Render\ColorXHTML`.

### Stylesheets

[](#stylesheets)

The Pygments renderer marks up parts of the output with `div` tags and classes. You'll then need to assign stlying to these tags.

#### SCSS/Compass

[](#scsscompass)

If you're already using Compass or SASS, there's an example Pygments stylesheet in Resources/public/css/\_pygments.scss. The default implementation uses the [Solarized](http://ethanschoonover.com/solarized) color scheme. You should be able to @import this stylesheet from one of your own.

#### Dynamic Styles

[](#dynamic-styles)

Pygments can provide one of several stylesheets to automatically color the output. A controller is provided that will output styles by calling `pygmentize -S `. To use the controller, reference it from your routing:

```
# app/config/routing.yml
varspool_pygments:
  resource: '@VarspoolPygmentsBundle/Controller/PygmentsController.php'
  type: annotation
```

Then include a CSS file in your page via the URL `/pygments//.css`. (e.g. /pygments/html/friendly.css).

Alternatively, you can get the styles as a string from the varspool\_pygments service:

```
$pygments_formatter = $this->container->get('varspool_pygments');
$styles = $pygments_formatter->getStyles('friendly');
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

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

Unknown

Total

1

Last Release

4249d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7972f8f29b6eda4b2ffa4d6e087a3551b2d909090d2bbcdb212b29a86fed07b?d=identicon)[dominics](/maintainers/dominics)

---

Top Contributors

[![dominics](https://avatars.githubusercontent.com/u/97427?v=4)](https://github.com/dominics "dominics (17 commits)")[![csanquer](https://avatars.githubusercontent.com/u/372677?v=4)](https://github.com/csanquer "csanquer (1 commits)")

---

Tags

markdownpygmentssundown

### Embed Badge

![Health badge](/badges/varspool-pygments-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/varspool-pygments-bundle/health.svg)](https://phpackages.com/packages/varspool-pygments-bundle)
```

###  Alternatives

[erusev/parsedown

Parser for Markdown.

15.0k151.8M732](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

2.9k404.0M702](/packages/league-commonmark)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[league/html-to-markdown

An HTML-to-markdown conversion helper for PHP

1.9k28.6M199](/packages/league-html-to-markdown)[cebe/markdown

A super fast, highly extensible markdown parser for PHP

1.0k32.5M136](/packages/cebe-markdown)

PHPackages © 2026

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