phore / markdown
Small dependency-free HTML and Markdown converters for PHP.
Requires
- php: >=8.5
- ext-dom: *
- ext-libxml: *
Requires (Dev)
- phpunit/phpunit: ^13.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-09 11:36:56 UTC
README
Small, dependency-free converters for common HTML and Markdown. The package intentionally supports a compact subset and falls back to readable text instead of trying to preserve every formatting detail.
use Phore\Markdown\Markdown; $markdown = Markdown::fromHtml('<h1>Hello</h1><p>A <strong>small</strong> example.</p>'); $html = Markdown::toHtml("# Hello\n\nA **small** example."); $text = Markdown::textFromHtml('<p>Hello <em>world</em>.</p>');
HTML input is treated as untrusted. Scripts, styles, forms, iframes, and images are removed during HTML-to-Markdown or text conversion. Markdown-to-HTML escapes raw HTML and accepts links only for http, https, and mailto URLs.
Supported syntax includes level 1–5 headings, paragraphs, line breaks, emphasis, strong text, inline code, links, unordered lists, and blockquotes.
Examples
examples/html-to-markdown.phpreads HTML elements and emits Markdown.examples/markdown-to-html.phpparses the supported Markdown elements and emits HTML.
Run either script after composer install, for example:
php examples/markdown-to-html.php