Parsedown PHP markdown parser
2026-11-07 17:18:32 UTC
Parsedown is a pure-PHP Markdown parser (version 1.8.0) written by Emanuil Rusev. [https://parsedown.org/]
What it does
It takes Markdown-formatted text and converts it into HTML.
The main entry point is:
PHP
$Parsedown = new Parsedown();
$html = $Parsedown->text($markdown);
Core capabilities
It implements a full Markdown-to-HTML conversion pipeline that handles:
Block-level elements
- Headers (# and Setext-style)
- Ordered and unordered lists (including nested)
- Code blocks (indented and fenced)
- Blockquotes
- Horizontal rules
- Tables
- HTML comments and raw markup (when allowed)
- Reference-style link definitions
Inline elements
- Emphasis / strong (* and _)
- Inline code
- Links and images (inline and reference-style)
- Autolinked URLs
- Strikethrough (~~)
- Escape sequences
- Special characters / entities
Configuration options
The class exposes several setters:
- setBreaksEnabled() – treat single newlines as <br>
- setMarkupEscaped() – escape raw HTML
- setUrlsLinked() – automatically turn bare URLs into links
- setSafeMode() – sanitize output (strips dangerous attributes/URLs)
- setStrictMode() – stricter CommonMark compliance for headers
Design notes
- Single-file, zero-dependency implementation
- Builds an intermediate element tree and then renders it to HTML
- Supports a safe-mode whitelist of URL schemes
- Can be used as a singleton via Parsedown::instance()
In short, this file is a complete, self-contained Markdown → HTML converter that you can drop into a PHP project.
Block-level elements
| Syntax | Description | Example |
|---|---|---|
| ATXHeaders | # to ###### | # Heading 1 |
| SetextHeaders | Underlinewith = (h1)or - (h2) | Heading ======= |
| UnorderedLists | *, +,or - | - item |
| OrderedLists | 1. / 1) style(anystartingnumber) | 1. item |
| NestedLists | Indentedlistitems | Supported |
| Blockquotes | > | > quoted text |
| IndentedCodeBlocks | 4+spacesor1tab | code |
| FencedCodeBlocks | ``` or ~~~ (withoptionallanguage) | ```php |
| HorizontalRules | 3+ *, -,or _ | --- |
| Tables | Pipetableswithoptionalalignment(:---, :---:, ---:) | | Header | | ------ | |
| HTMLComments | <!-- ... --> | Supported(whenmarkupnotescaped) |
| RawHTMLBlocks | Mostblock-levelHTMLtags | Supported(whennotinsafe/escapedmode) |
| LinkReferences | [id]: url "title" | Definitionstylelinks |
Inline elements
| Syntax | Description | Example |
|---|---|---|
| Emphasis | *text* or _text_ | italic |
| Strong | **text** or __text__ | bold |
| InlineCode | `code` | code |
| Links | [text](url) or [text](url "title") | [link](https://example.com) |
| ReferenceLinks | [text][id] | Usespreviouslydefinedreferences |
| Images |  or  |  |
| Autolinks | BareURLs(whenenabled) | https://example.com |
| URLTags | <https://example.com> | Angle-bracketURLs |
| EmailTags | <user@example.com> | Angle-bracketemails |
| Strikethrough | ~~text~~ | |
| EscapeSequences | \ beforespecialcharacters | \*not italic\* |
| SpecialCharacters/Entities | &...; | &, {,etc. |
| RawHTML | InlineHTMLtags | Supported(whennotescaped/safemode) |
Notable behaviors / options that affect syntax
- Line breaks: Single newlines become <br> only if setBreaksEnabled(true) is used.
- Safe mode (setSafeMode(true)): Restricts URLs to a whitelist and strips dangerous attributes.
- Strict mode: Makes ATX headers require a space after the #.
- Nested emphasis, mixed */_, and most CommonMark edge cases are supported.
- Tables require a header row + separator row.
- Fenced code blocks support an optional language class (language-xxx).
This covers essentially all of the syntax the class actually implements.