cradeq / commonmark-strikethrough-sub-sup-extension
Adds support for strikethrough, subscript and superscript in Markdown (using `<del>`, `<sub>` and `<sup>` HTML tags).
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:commonmark-extension
pkg:composer/cradeq/commonmark-strikethrough-sub-sup-extension
Requires
- php: ^8.0
- league/commonmark: ^2.8
Requires (Dev)
- phpunit/phpunit: ^13.0
README
This package adds support for subscript and superscript in Markdown (using <sub> and <sup> HTML tags). This package also duplicates the logic used in the League Strikethrough Extension (which generates <del> tags).
There is no official spec that supports both subscript and strikethrough. As they both typically use the tilde character (~), we follow the extended syntax of Markdown Guide. That means that strikethrough with only one tilde is necessarily NOT supported. Subscript and strikethrough can be nested, similar to how emphasis works (~Subscript ~~Subscript and striked~~~).
Added markdown features
| Name | Markdown | Result |
|---|---|---|
| Superscript | ^Text^ |
<sup>Text</sup> |
| Subscript | ~Text~ |
<sub>Text</sub> |
| Strikethrough | ~~Text~~ |
<del>Text</del> |
Install
This project can be installed via composer:
composer require cradeq/commonmark-strikethrough-sub-sup-extension
Usage
use Cradeq\CommonMark\StrikethroughSubExtension; use Cradeq\CommonMark\SupExtension; use League\CommonMark\Environment\Environment; use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; $environment = new Environment(); $environment->addExtension(new CommonMarkCoreExtension); $environment->addExtension(new StrikethroughSubExtension); $environment->addExtension(new SupExtension);