blizzard-fs/md2html
最新稳定版本:v1.0.0
Composer 安装命令:
composer require blizzard-fs/md2html
包简介
Standalone Markdown to HTML parser. Pure PHP, no dependencies. CommonMark + GFM with optional Carbon.now.sh-style code blocks.
README 文档
README
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
Composer
composer require blizzard-fs/md2html
Manual
Clone the repo and require the entry point directly:
git clone https://github.com/Blizzard-fs/md2html.git
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
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
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.
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
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
MarkdownParser (facade)
├── ParseContext (shared state)
├── InlineParser(context, renderer)
├── BlockParser(context, inlineParser, renderer)
└── RendererInterface
├── PlainHtmlRenderer (default)
└── CarbonHtmlRenderer (composes PlainHtmlRenderer)
Strategy pattern with composition. CarbonHtmlRenderer delegates everything except codeBlock() to PlainHtmlRenderer - no inheritance.
Requirements
- PHP 8.1+
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-10