The attributes extension adds a syntax to define attributes on the various HTML elements in CommonMark PHP implementation.

Installs: 25 796

Dependents: 15

Suggesters: 0

Stars: 26

Watchers: 3

Forks: 13

Open Issues: 5


0.5.0 2016-09-26 08:18 UTC


Packagist Build Status StyleCI Scrutinizer Code Quality Code Coverage SensioLabsInsight

The Attributes extension adds a syntax to define attributes on the various HTML elements in markdown’s output.


This project can be installed via Composer:

composer require webuni/commonmark-attributes-extension


use League\CommonMark\Converter;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use Webuni\CommonMark\AttributesExtension\AttributesExtension;

$environment = Environment::createCommonMarkEnvironment();
$environment->addExtension(new AttributesExtension());

$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));

echo $converter->convertToHtml('# Hello World!');


The basic syntax was inspired by Kramdown‘s Attribute Lists feature.

You can assign any attribute to a block-level element. Just directly prepend or follow the block with a block inline attribute list. That consists of a left curly brace, optionally followed by a colon, the attribute definitions and a right curly brace:

> A nice blockquote
{: title="Blockquote title"}

{#id .class}
## Header

As with a block-level element you can assign any attribute to a span-level elements using a span inline attribute list, that has the same syntax and must immediately follow the span-level element:

This is *red*{style="color: red"}.