PHPackages                             8fold/commonmark-fluent-markdown - 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. 8fold/commonmark-fluent-markdown

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

8fold/commonmark-fluent-markdown
================================

A fluent API for CommonMark by the PHP League

1.2.0(3y ago)02.6k[1 issues](https://github.com/8fold/commonmark-fluent-markdown/issues)1MITPHPPHP ^8.1

Since Oct 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/8fold/commonmark-fluent-markdown)[ Packagist](https://packagist.org/packages/8fold/commonmark-fluent-markdown)[ GitHub Sponsors](https://github.com/8fold)[ GitHub Sponsors](https://github.com/joshbruce)[ RSS](/packages/8fold-commonmark-fluent-markdown/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (28)Used By (1)

8fold Fluent Markdown for CommonMark
====================================

[](#8fold-fluent-markdown-for-commonmark)

A fluent API for use with the highly-extensible [CommonMark parser](https://commonmark.thephpleague.com/2.0/) from the league of extraordinary packages.

We try to put off instantiation and execution until the last possible moment.

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

[](#installation)

```
composer require 8fold/commonmark-fluent-markdown
```

Usage
-----

[](#usage)

⚠️ Warning: Users of this library are responsible for sanitizing content.

There are two entry classes:

1. Markdown: Does not follow strictly follow conventions established by the [League CommonMark](https://commonmark.thephpleague.com).
2. FluentCommonMark: Tries to mirror the conventions of League CommonMark in a fluent way.

The naming convention for methods that are not part of the League CommonMark implementation follow the convention established by [PSR-7](https://www.php-fig.org/psr/psr-7/).

Methods prefixed by the word `with` will return a new instance to facilitate immutability.

### Markdown

[](#markdown)

The Markdown class makes some presumptions the FluentCommonMark class does not:

1. You will be using the CommonMarkCoreExtension.
2. There will always be the potential for front matter; therefore, the FrontMatterExtension will always be used to separate front matter from the body.

The Markdown class uses the the default configuration provided by CommonMark with modifications recommended by the [security](https://commonmark.thephpleague.com/2.0/security/) page of the CommonMark documentation.

The Markdown class also affords users the ability to use the [8fold CommonMark Abbreviations](https://github.com/8fold/commonmark-abbreviations) and [8fold CommonMark Accessible Heading Permalinks](https://github.com/8fold/commonmark-accessible-heading-permalinks) extensions whereas FluentCommonMark is strictly vanilla [League CommonMark](https://commonmark.thephpleague.com).

Write some markdown:

```
# Markdown

Woohoo!
```

Pass the markdown into the `Markdown` class and ask for the `convertedContent`:

```
use Eightfold\Markdown\Markdown;

print Markdown::create()->convert($markdown);
```

Output:

```
Markdown
Woohoo!
```

```
use Eightfold\Markdown\Markdown;

print Markdown::create()->minified()->convert($markdown);
```

```
MarkdownWoohoo!
```

You can have markdown that is nothing but front matter as well.

```
---
title: The title
---
```

```
use Eightfold\Markdown\Markdown;

print Markdown::create()->minified()->getFrontMatter($markdown);
```

Output:

```
[
  'title' => 'The title'
]
```

The Markdown extends the FluentCommonMark class.

### FluentMarkdown

[](#fluentmarkdown)

The FluentMarkdown class is designed to mimic the behavior and feel of the CommonMark library. There are additional methods in place to facilitate the fully fluent nature of this library.

### Container

[](#container)

The Container class is a singleton that may contain one or more converter configurations.

This is useful if you find yourself instantiating multiple markdown converters:

1. With each server request.
2. With the same configuration and options.

By placing those converters in the Container, they only need to be instantiated once and you should see a performance increase by doing so.

```
Container::instance()->addConverter(
	Markdown::create()->abbreviations()
)->addConverter(
	FluentCommonMark::create()->descriptionLists()
);

// Returns the Markdown instance (first converter in list)
$html = Container::instance()->converter()->convert('');

// Returns HTML converted by FluentCommonMark insance
$html = Container::instance()->converter()->convertToHtml('');

```

### Extensions

[](#extensions)

Each internal [CommonMark extension](https://commonmark.thephpleague.com/2.0/extensions/overview/) is available via the fluent API along with [8fold Abbreviations](https://github.com/8fold/commonmark-abbreviations):

```
---
title: Front matter
---

~~strikethrough from GitHub Flavored Markdown~~

An [.abbr](abbreviation) from 8fold Abbreviations.
```

Setting the extensions and printing the result:

```
use Eightfold\Markdown\Markdown;
use Eightfold\Markdown\FluentCommonMark;

print Markdown::create()
  ->minified()
  ->gitHubFlavoredMarkdown()
  ->abbreviations()
  ->convert($markdown);

print FluentCommonMark::create()
  ->commonMarkCore()
  ->gitHubFlavoredMarkdown()
  ->abbreviations()
  ->convertToHtml($markdown)
  ->getContent();
```

The result:

```
strikethrough from GitHub Flavored MarkdownAn abbr from 8fold Abbreviations.

strikethrough from GitHub Flavored Markdown
An abbr from 8fold Abbreviations.
```

If the [extension accepts a configuration](https://commonmark.thephpleague.com/2.0/extensions/disallowed-raw-html/), you can pass it into the method and the primary configuration will be modified accordingly.

```
use Eightfold\Markdown\Markdown;

print Markdown::create($markdown)
  ->disallowedRawHtml([
    'disallowed_tags' => ['div']
  ]);
```

Not passing in a configuration results in using the default established by the CommonMark library.

Details
-------

[](#details)

This is actually our third foray into wrapping CommonMark.

CommonMark has been a staple in 8fold web development since inception. As we've progressed and continued to slowly evolve our own XML and HTML generating packages and used those solutions in an array of websites, CommonMark has been featured front and center, as it were.

Given how much CommonMark is used in our various projects and our desire to be loosely coupled with any solutions we don't write ourselves, I think we've come to a solution that accomplishes both those missions.

Minimal code to start, configure, and render HTML. A consistent API to reduce impact as CommonMark continues to evolve.

Other
-----

[](#other)

- [Code of Conduct](https://github.com/8fold/commonmark-fluent-markdown/blob/main/.github/CODE_OF_CONDUCT.md)
- [Contributing](https://github.com/8fold/commonmark-fluent-markdown/blob/main/.github/CONTRIBUTING.md)
- [Governance](https://github.com/8fold/commonmark-fluent-markdown/blob/main/.github/GOVERNANCE.md)
- [Versioning](https://github.com/8fold/commonmark-fluent-markdown/blob/main/.github/VERSIONING.md)
- [Security](https://github.com/8fold/commonmark-fluent-markdown/blob/main/.github/SECURITY.md)
- [Coding Standards and Style](https://github.com/8fold/commonmark-fluent-markdown/blob/main/.github/coding-standards-and-styles.md)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~31 days

Recently: every ~127 days

Total

20

Last Release

1099d ago

Major Versions

0.10.9 → 1.0.02022-07-23

PHP version history (3 changes)0.9.0PHP ^7.4 || ^8.0

0.10.0PHP ^8.0

1.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ff7aa36dc04c5b535cd71eadbf66038401edde0c9dfaa688bec4fc16c6d7e8b?d=identicon)[eightfold](/maintainers/eightfold)

---

Top Contributors

[![joshbruce](https://avatars.githubusercontent.com/u/15252830?v=4)](https://github.com/joshbruce "joshbruce (85 commits)")

---

Tags

commonmarkmarkdownphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/8fold-commonmark-fluent-markdown/health.svg)

```
[![Health](https://phpackages.com/badges/8fold-commonmark-fluent-markdown/health.svg)](https://phpackages.com/packages/8fold-commonmark-fluent-markdown)
```

###  Alternatives

[mnapoli/front-yaml

2895.6M45](/packages/mnapoli-front-yaml)[daux/daux.io

Documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly

825191.0k1](/packages/daux-dauxio)[spatie/sheets

Store &amp; retrieve your static content in plain text files

30187.7k4](/packages/spatie-sheets)[prezet/prezet

Prezet: Markdown Blogging for Laravel

2969.8k2](/packages/prezet-prezet)[prohalexey/the-choice

253.3k](/packages/prohalexey-the-choice)[opensoft/simple-serializer

Simple Serializer

1914.2k1](/packages/opensoft-simple-serializer)

PHPackages © 2026

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