Download the PHP package php-markdown/parser without Composer
On this page you can find all versions of the php package php-markdown/parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-markdown/parser
More information about php-markdown/parser
Files in php-markdown/parser
Package parser
Short Description Lightweight standalone CommonMark Markdown to HTML5 parser — no external dependencies
License MIT
Informations about the package parser
php-markdown
A lightweight, standalone PHP library (8.2–8.4) that parses CommonMark-flavored Markdown and converts it into clean, semantic HTML5. Zero runtime dependencies.
Requirements
- PHP 8.2 to 8.4
- PHP extensions:
ctype,intl,mbstring - No external packages required for core usage
Installation
Via Composer (recommended)
Manual (no Composer)
Copy the src/ directory into your project, then require the files in this order:
Try it — Docker Playground
No PHP installation required. From the project root:
Open http://localhost:8080 in your browser. See playground/README.md
for full setup details, port-override instructions, and caveats.
Quick Start
Front Matter
parse() also accepts front matter — it strips the block silently, so existing code needs no changes.
GFM Tables
Raw HTML pass-through
Raw HTML is escaped by default (XSS-safe). Opt in to sanitized pass-through with allowRawHtml: true:
Options
All constructor arguments are optional and named:
A custom NormalizerInterface can also be passed as normalizer: (defaults to IcuNormalizer).
Supported Features
Block elements
| Feature | Syntax | Output |
|---|---|---|
| Headings H1–H6 (ATX) | # Heading … ###### Heading (empty content allowed: #) |
<h1> … <h6> |
| Headings H1–H2 (Setext) | Heading\n=== / Heading\n--- (multiline content supported) |
<h1> / <h2> |
| Paragraph | plain text (soft line breaks preserved as newlines) | <p> |
| Blockquote (nested) | > text |
<blockquote> |
| Unordered list | - item / * item / + item |
<ul><li> |
| Ordered list | 1. item / 1) item (start number kept: 3. item) |
<ol><li> / <ol start="3"> |
| Nested lists | indented - item inside list item |
<ul> inside <li> |
| Task list | - [x] done / - [ ] todo |
<li><input type="checkbox" …> |
| Fenced code block | lang … or| |
|
| Mermaid diagram | mermaid … |` |
|
| Indented code block | 4-space / 1-tab indent | <pre><code> |
| Horizontal rule | --- / *** / ___ |
<hr /> |
| GFM Table | \| col \| col \| + separator row |
<table><thead><tbody> with align |
| Front Matter | ---\nkey: value\n--- at file top |
parsed into meta array via parseWithMeta() |
| Raw HTML block | <div>…</div> |
escaped (default) or sanitized (allowRawHtml: true) |
| Two-column layout | :::columns … \|\|\| … ::: |
<div class="grid grid-cols-2 …"> |
| Footnote definition | [^label]: body |
rendered in <section class="footnotes"> |
Inline elements
| Feature | Syntax | Output |
|---|---|---|
| Bold | **text** or __text__ |
<strong> |
| Italic | *text* or _text_ |
<em> |
| Strikethrough | ~~text~~ |
<del> |
| Inline code | `code` | <code> |
|
| Link (inline) | [text](url) or [text](<url>), optional title in "…", '…' or (…) |
<a href="…"> |
| Link (reference) | [text][ref] with [ref]: url or [ref]: <url> definition |
<a href="…"> |
| Image | ,  or ![alt][ref] |
<img src="…" alt="…" /> |
| Autolink | <https://…> or <[email protected]> |
<a href="…"> |
| Hard line break | two trailing spaces + newline | <br /> |
| HTML entity / numeric reference | ©, *, * |
decoded to the character, then re-escaped |
| Backslash escape | \*not emphasis\* |
literal punctuation |
| Raw HTML inline | <span class="x"> |
escaped (default) or sanitized (allowRawHtml: true) |
| Footnote reference | [^label] |
<sup><a href="#fn-…"> |
Architecture
The library is built as a three-stage pipeline. Each stage is independent and testable in isolation.
| Class | Responsibility |
|---|---|
Lexer |
Tokenises the input line by line into Token[] (tabs expanded to 4-column stops, CommonMark §2.1) |
InlineParser |
Recursive delimiter-stack scanner for inline elements |
Parser |
Consumes Token[] and builds a DocumentNode AST |
HtmlRenderer |
Traverses the AST and emits escaped HTML; void elements are self-closed (<br />, <hr />, <img … />) as in the CommonMark spec |
HtmlSanitizer |
DOM-based sanitizer used when allowRawHtml: true |
FrontMatterParser |
Extracts and parses the YAML-subset front matter block |
IcuNormalizer |
NFC-normalizes input via PHP intl if available |
MarkdownParser |
Public façade — wires all stages together |
All AST nodes are immutable (readonly properties, PHP 8.2+).
Security
All user-supplied content is escaped via htmlspecialchars(ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') before being written to output. This covers:
- Text content (all
TextNodevalues) - Code content (
CodeNode,FencedCodeNode) - HTML attributes (
href,src,alt,title,class)
Dangerous URL schemes (javascript:, vbscript:, data:) in links are detected at parse time and rendered as literal text rather than <a> elements.
Raw HTML is escaped by default. Passing allowRawHtml: true enables DOM-based sanitization via HtmlSanitizer:
- Forbidden tags (
script,iframe,form, etc.) are removed with their entire subtree. - Unknown tags are unwrapped (children promoted).
- All
on*event handlers,style, andjavascript:/data:URL attributes are stripped. target="_blank"links getrel="noopener"injected automatically.
Resource limits: input is limited to maxBytes (1 MiB by default). Short table rows are completed with empty cells up to 100,000 cells per document; past that, they stay short. Parse time stays roughly linear in input size on pathological input (tests/Security). Memory use is high at the limit: a 1 MiB document needed from about 100 MB to 800 MB in stress tests, depending on its content, so use a lower maxBytes with PHP's default memory_limit of 128 MB.
Testing
Benchmark
benchmark/ compares this library with league/commonmark, Parsedown and michelf/php-markdown on the same generated document (headings, emphasis, links, lists, fenced code, blockquote, table) in three sizes. It installs the library from the parent directory as a Composer path repository, so it measures your working copy.
Sample results (PHP 8.2.29, Windows x64, no OPcache/JIT, best time per parser over 6 runs), lower is better:
| Document | php-markdown/parser | Parsedown | michelf/php-markdown | league/commonmark |
|---|---|---|---|---|
| small (1 KB, 1,000 runs) | 0.57 ms | 0.38 ms | 0.45 ms | 2.01 ms |
| medium (10 KB, 200 runs) | 4.30 ms | 4.75 ms | 4.72 ms | 14.47 ms |
| large (82 KB, 20 runs) | 35.73 ms | 32.61 ms | 37.05 ms | 117.58 ms |
Timings vary by machine and between runs. On the small document, the order was the same in every run. On the medium and large documents, the three fastest parsers swapped places from run to run, so their differences there are within the noise. The memory column printed by the script is the memory_get_usage() delta across the loop, not peak usage, so it is not reported here.
Limitations
The following are not supported:
- LaTeX / math (
$…$,$$…$$) - Definition lists
- Custom HTML attributes in Markdown syntax
License
MIT © 2026
All versions of parser with dependencies
ext-ctype Version *
ext-intl Version *
ext-mbstring Version *