PHP Markdown
Convert Markdown and Markdown Extra text into HTML in PHP.
Repository Health
Technical Analysis
PHP Markdown is a library by Michel Fortin that parses Markdown-formatted text and converts it to HTML. It is a faithful PHP port of John Gruber’s original Markdown.pl, and ships with a second parser, Markdown Extra, that adds widely-used extensions such as tables, footnotes, definition lists, fenced code blocks, and attribute blocks.
The library exposes a tiny, stateless API — call Markdown::defaultTransform() or MarkdownExtra::defaultTransform() on a string of Markdown and get HTML back. Parser instances are configurable for things like HTML sanitization and hard line breaks, making it a dependable, zero-runtime-dependency choice for rendering user-authored content in PHP applications.
What You Get
- A classic Markdown parser faithful to the original Markdown.pl syntax
- A Markdown Extra parser with tables, footnotes, and fenced code blocks
- A one-call static API (defaultTransform) plus configurable parser instances
- Options for HTML sanitization, hard line breaks, and header id prefixes
- Zero runtime dependencies and a MarkdownInterface for swappable implementations
Common Use Cases
- Rendering user-authored comments, posts, or documentation written in Markdown
- Powering the content layer of a blog or CMS built in PHP
- Converting Markdown files to HTML during a static-site or docs build
- Adding tables and footnotes to formatted text via Markdown Extra
Under The Hood
Architecture - The parser is implemented as two main classes under the Michelf namespace: Markdown (Michelf/Markdown.php) implements the original syntax, and MarkdownExtra (Michelf/MarkdownExtra.php) extends it with additional block and span handlers. Both implement MarkdownInterface. Parsing is a multi-pass, regex-driven pipeline: block-level gamut methods (headers, lists, code blocks, tables) run first, then span-level gamut methods (links, emphasis, code spans) transform inline content, with hash placeholders protecting already-processed HTML from re-parsing.
Tech Stack - Pure PHP (>=7.4) with no runtime dependencies. Development tooling includes PHPUnit for tests, PHPStan (level 5) for static analysis, and php-cs-fixer for code style.
Code Quality - The code is a long-lived, carefully maintained port with a dedicated test/ suite of Markdown-to-HTML fixture comparisons and PHPStan analysis wired into composer scripts. The regex-heavy gamut approach is inherited from the reference implementation; it is dense but battle-tested and stable across many years of use.
API Design - The public surface is deliberately minimal and forgiving: a single static call (defaultTransform) covers the common case, while constructing a Markdown or MarkdownExtra instance exposes configurable public properties for sanitization, hard breaks, and id prefixes. Getting started requires essentially no boilerplate.