PHPackages                             blizzard-fs/md2html - 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. blizzard-fs/md2html

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

blizzard-fs/md2html
===================

Standalone Markdown to HTML parser. Pure PHP, no dependencies. CommonMark + GFM with optional Carbon.now.sh-style code blocks.

v1.1.0(1mo ago)00MITPHPPHP &gt;=8.1

Since Jun 10Pushed 1mo agoCompare

[ Source](https://github.com/Blizzard-fs/md2html)[ Packagist](https://packagist.org/packages/blizzard-fs/md2html)[ Docs](https://github.com/Blizzard-fs/md2html)[ RSS](/packages/blizzard-fs-md2html/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

md2html
=======

[](#md2html)

Standalone Markdown to HTML parser. Pure PHP, no dependencies.

Supports CommonMark and GitHub Flavored Markdown (GFM) with an optional Carbon.now.sh-style renderer for code blocks.

Install
-------

[](#install)

### Composer

[](#composer)

```
composer require blizzard-fs/md2html
```

### Manual

[](#manual)

Clone the repo and require the entry point directly:

```
git clone https://github.com/Blizzard-fs/md2html.git
```

CLI Usage
---------

[](#cli-usage)

```
# File to stdout
php md2html.php input.md

# File to file
php md2html.php input.md output.html

# Stdin
echo "# Hello" | php md2html.php

# With Carbon-styled code blocks
php md2html.php input.md --carbon
php md2html.php input.md --carbon output.html

# Options
php md2html.php input.md --safe --heading-ids --nofollow
php md2html.php input.md --wrap --title "My Page" --css "body{max-width:800px}"
php md2html.php input.md --carbon --wrap --heading-ids --hard-breaks
```

### CLI Options

[](#cli-options)

FlagDescription`--carbon`Carbon.now.sh-style code blocks`--safe`Strip raw HTML blocks`--heading-ids`Generate `id` attributes on headings`--hard-breaks`Treat newlines as ```--nofollow`Add `rel="nofollow noopener"` to links`--wrap`Wrap output in full HTML document`--title `Document title (requires `--wrap`)`--css `Custom CSS (requires `--wrap`)`--max-nesting `Max block nesting depth (default `10`)PHP Usage
---------

[](#php-usage)

```
require_once __DIR__ . '/md2html/src/RendererInterface.php';
require_once __DIR__ . '/md2html/src/PlainHtmlRenderer.php';
require_once __DIR__ . '/md2html/src/ParseContext.php';
require_once __DIR__ . '/md2html/src/InlineParser.php';
require_once __DIR__ . '/md2html/src/BlockParser.php';
require_once __DIR__ . '/md2html/src/MarkdownParser.php';

$parser = new MarkdownParser();
$html = $parser->parse('# Hello **world**');
```

With Composer autoloading:

```
require_once __DIR__ . '/vendor/autoload.php';

use BlizzardFs\Md2Html\MarkdownParser;

$parser = new MarkdownParser();
$html = $parser->parse('# Hello **world**');
```

### Carbon renderer

[](#carbon-renderer)

```
use BlizzardFs\Md2Html\CarbonHtmlRenderer;
use BlizzardFs\Md2Html\MarkdownParser;

$renderer = new CarbonHtmlRenderer();
$parser = new MarkdownParser($renderer);
$html = $parser->parse($markdown);
```

Code blocks render with macOS-style window chrome, dark background, and language labels. CSS is emitted once, inline.

### Options

[](#options)

```
use BlizzardFs\Md2Html\MarkdownParser;
use BlizzardFs\Md2Html\ParserOptions;

$options = (new ParserOptions())
    ->setHeadingIds(true)
    ->setNoFollowLinks(true)
    ->setSafeMode(true);

$parser = new MarkdownParser(options: $options);
$html = $parser->parse($markdown);
```

OptionDefaultDescription`setWrapDocument(bool)``false`Wrap output in `` document`setDocumentTitle(string)``''``` for document wrapper`setDocumentCss(string)``''`Custom `` in document ```setSafeMode(bool)``false`Strip raw HTML blocks`setHeadingIds(bool)``false`Generate `id` slugs on headings`setHardBreaks(bool)``false`Treat newlines as ```setNoFollowLinks(bool)``false`Add `rel="nofollow noopener"` to links`setMaxNestingLevel(int)``10`Limit recursion depth for nested blocksImplement `OptionsInterface` to provide your own options logic. Custom renderers that need access to the active options implement `OptionsAwareInterface` (a `setOptions()` method); the parser injects options into any renderer that does.

### Custom renderer

[](#custom-renderer)

Implement `RendererInterface` to control all HTML output:

```
use BlizzardFs\Md2Html\RendererInterface;
use BlizzardFs\Md2Html\MarkdownParser;

class MyRenderer implements RendererInterface
{
    // 22 methods - one per element type
    // See src/RendererInterface.php for the full contract
}

$parser = new MarkdownParser(new MyRenderer());
```

Supported Elements
------------------

[](#supported-elements)

**Block-level:** headings (ATX + setext), paragraphs, fenced and indented code blocks, blockquotes (nested), tables (with alignment), ordered and unordered lists (nested, loose/tight), task lists, horizontal rules, HTML passthrough, footnote sections.

**Inline:** bold, italic, bold-italic, strikethrough, inline code, links (inline + reference), images, autolinks, email links, footnote references, backslash escapes, line breaks.

**GFM extensions:** tables, strikethrough, task lists, autolinks, underscore-in-word handling (`foo_bar_baz` stays literal).

Architecture
------------

[](#architecture)

```
MarkdownParser (facade)
  ├── OptionsInterface (configuration)
  ├── ParseContext (shared state)
  ├── InlineParser(context, renderer, options)
  ├── BlockParser(context, inlineParser, renderer, options)
  └── RendererInterface
        ├── PlainHtmlRenderer (default, options-aware)
        └── CarbonHtmlRenderer (composes PlainHtmlRenderer)

```

Strategy pattern with composition. `CarbonHtmlRenderer` delegates everything except `codeBlock()` to `PlainHtmlRenderer` - no inheritance.

Requirements
------------

[](#requirements)

- PHP 8.1+

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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 ~0 days

Total

2

Last Release

45d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/58548607?v=4)[Stefan Tomà](/maintainers/Blizzard-fs)[@Blizzard-fs](https://github.com/Blizzard-fs)

---

Top Contributors

[![Blizzard-fs](https://avatars.githubusercontent.com/u/58548607?v=4)](https://github.com/Blizzard-fs "Blizzard-fs (20 commits)")

---

Tags

parserhtmlmarkdowncarbongfmcommonmark

### Embed Badge

![Health badge](/badges/blizzard-fs-md2html/health.svg)

```
[![Health](https://phpackages.com/badges/blizzard-fs-md2html/health.svg)](https://phpackages.com/packages/blizzard-fs-md2html)
```

###  Alternatives

[league/commonmark

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

3.0k437.5M1.1k](/packages/league-commonmark)[erusev/parsedown

Parser for Markdown.

15.1k156.8M875](/packages/erusev-parsedown)[masterminds/html5

An HTML5 parser and serializer.

1.8k269.7M327](/packages/masterminds-html5)[league/html-to-markdown

An HTML-to-markdown conversion helper for PHP

1.9k32.2M327](/packages/league-html-to-markdown)[cebe/markdown

A super fast, highly extensible markdown parser for PHP

1.0k34.1M150](/packages/cebe-markdown)[jbroadway/slimdown

A simple regex-based Markdown parser.

348.0k](/packages/jbroadway-slimdown)

PHPackages © 2026

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