Search by

ows / commonmark-sup-sub-extensions

jcisioSylry

A sup/sub extension for CommonMark PHP implementation

Package info

github.com/OWS/commonmark-sup-sub-extensions

Homepage

Type:commonmark-extension

pkg:composer/ows/commonmark-sup-sub-extensions

Statistics

Installs: 7 789

Dependents: 1

Suggesters: 0

Stars: 10

Open Issues: 3

3.0.0-RC2 2026-10-30 12:32 UTC

This package is auto-updated.

Last update: 2026-10-30 13:33:42 UTC


README

Build Status

This library adds support of superscript and subscript (<sup> and <sub> HTML tags) to league/commonmark.

Versions compatibility

  • 3.x is compatible with league/commonmark 2.x (2.10.2+) and requires PHP 8.3+ (recommended version)
  • 2.x is compatible with league/commonmark 1.x
  • 1.x is compatible with league/commonmark 0.17.x and 0.18.x and will no longer be supported

Installation

This project can be installed via Composer:

$ composer require ows/commonmark-sup-sub-extensions

Usage

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Ows\CommonMark\SupSubExtension\SupExtension;
use Ows\CommonMark\SupSubExtension\SubExtension;

$environment = new Environment();
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new SupExtension());
$environment->addExtension(new SubExtension());

$converter = new MarkdownConverter($environment);
echo $converter->convert('10^2^ H~2~O');

See league/commonmark extensions documentation.

Note: SubExtension cannot be used together with the StrikethroughExtension (also included in GithubFlavoredMarkdownExtension), as both use the ~ delimiter.

Syntax

Code:

10^2^
10~2~

Result:

10<sup>2</sup>
10<sub>2</sub>

As in Pandoc, spaces are not allowed between delimiters: use &nbsp; instead (P~a&nbsp;cat~). Spaces inside nested elements are allowed (^[a link](https://example.com)^).