承接 blizzard-fs/md2html 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blizzard-fs/md2html

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

# Options
php md2html.php input.md --safe --heading-ids --nofollow
php md2html.php input.md --wrap --title "My Page" --css "body{max-width:800px}"
php md2html.php input.md --carbon --wrap --heading-ids --hard-breaks

CLI Options

Flag Description
--carbon Carbon.now.sh-style code blocks
--safe Strip raw HTML blocks
--heading-ids Generate id attributes on headings
--hard-breaks Treat newlines as <br>
--nofollow Add rel="nofollow noopener" to links
--wrap Wrap output in full HTML document
--title <str> Document title (requires --wrap)
--css <str> Custom CSS (requires --wrap)
--max-nesting <n> Max block nesting depth (default 10)

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.

Options

use BlizzardFs\Md2Html\MarkdownParser;
use BlizzardFs\Md2Html\ParserOptions;

$options = (new ParserOptions())
    ->setHeadingIds(true)
    ->setNoFollowLinks(true)
    ->setSafeMode(true);

$parser = new MarkdownParser(options: $options);
$html = $parser->parse($markdown);
Option Default Description
setWrapDocument(bool) false Wrap output in <!DOCTYPE html> document
setDocumentTitle(string) '' <title> for document wrapper
setDocumentCss(string) '' Custom <style> in document <head>
setSafeMode(bool) false Strip raw HTML blocks
setHeadingIds(bool) false Generate id slugs on headings
setHardBreaks(bool) false Treat newlines as <br>
setNoFollowLinks(bool) false Add rel="nofollow noopener" to links
setMaxNestingLevel(int) 10 Limit recursion depth for nested blocks

Implement OptionsInterface to provide your own options logic. Custom renderers that need access to the active options implement OptionsAwareInterface (a setOptions() method); the parser injects options into any renderer that does.

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)
  ├── OptionsInterface (configuration)
  ├── ParseContext (shared state)
  ├── InlineParser(context, renderer, options)
  ├── BlockParser(context, inlineParser, renderer, options)
  └── RendererInterface
        ├── PlainHtmlRenderer (default, options-aware)
        └── CarbonHtmlRenderer (composes PlainHtmlRenderer)

Strategy pattern with composition. CarbonHtmlRenderer delegates everything except codeBlock() to PlainHtmlRenderer - no inheritance.

Requirements

  • PHP 8.1+

License

MIT

blizzard-fs/md2html 适用场景与选型建议

blizzard-fs/md2html 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「parser」 「markdown」 「html」 「carbon」 「gfm」 「commonmark」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 blizzard-fs/md2html 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blizzard-fs/md2html 我们能提供哪些服务?
定制开发 / 二次开发

基于 blizzard-fs/md2html 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10