承接 tomvdpeet/markdown-negotiation-bundle 相关项目开发

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

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

tomvdpeet/markdown-negotiation-bundle

Composer 安装命令:

composer require tomvdpeet/markdown-negotiation-bundle

包简介

Symfony bundle to negotiate Markdown responses from HTML routes.

README 文档

README

Symfony bundle that negotiates Markdown responses for opted-in routes.

This bundle was created for the article Getting agent-ready with Symfony.

Installation

composer require tomvdpeet/markdown-negotiation-bundle

Symfony Flex enables the bundle automatically. If you do not use Flex, register it manually in config/bundles.php:

TomvdPeet\MarkdownNegotiationBundle\MarkdownNegotiationBundle::class => ['all' => true],

Usage

Enable Markdown negotiation per route with the markdown route option:

use Symfony\Component\Routing\Attribute\Route;

#[Route('/docs', name: 'docs', options: ['markdown' => true])]
public function docs(): Response
{
    return $this->render('docs/index.html.twig');
}

Requests that prefer text/markdown over text/html receive a converted Markdown response:

Accept: text/markdown, text/html;q=0.5

HTML remains the response format when it has a higher or equal quality:

Accept: text/html, text/markdown;q=0.5

Wildcard-only requests also keep HTML:

Accept: */*

Debug Query Parameter

When kernel.debug is enabled, you can force Markdown negotiation from a browser by adding _markdown to the URL:

/docs?_markdown

This behaves like the request preferred text/markdown, but only in debug kernels. Production kernels keep the normal Accept header behavior and do not check the query string.

The query parameter name is configurable:

markdown_negotiation:
    debug_query_parameter: markdown_preview

Set it to null or false to disable the debug shortcut.

Behavior

The bundle only converts responses when all of these conditions match:

  • the current route has options: ['markdown' => true]
  • the request is the main request
  • text/markdown has a strictly higher effective Accept quality than text/html
  • the response is successful
  • the response content type is text/html
  • the response is not streamed or binary

Routes without the option return immediately through an optimized route map. Responses that already use text/markdown are left untouched.

Before conversion, the HTML is cleaned to remove common layout/decorative nodes such as head, nav, script, style, footer, and aside. Markdown-relevant tags such as headings, paragraphs, links, images, code, lists, tables, and blockquotes are preserved for conversion.

Links and images keep their href and src values. Absolute same-host URLs are normalized to relative URLs before conversion.

Manual Markdown Responses

Use MarkdownResponse when a controller already has Markdown and should return it directly:

use TomvdPeet\MarkdownNegotiationBundle\Http\MarkdownResponse;

return new MarkdownResponse("# Hello\n\nManual Markdown.");

This sets Content-Type: text/markdown; charset=UTF-8 and does not add Vary: Accept.

If the response was selected through content negotiation, use the named constructor:

return MarkdownResponse::negotiated("# Hello");

That also adds Vary: Accept.

For custom controller logic, inject MarkdownNegotiator:

use Symfony\Component\HttpFoundation\Request;
use TomvdPeet\MarkdownNegotiationBundle\Http\MarkdownNegotiator;
use TomvdPeet\MarkdownNegotiationBundle\Http\MarkdownResponse;

public function docs(Request $request, MarkdownNegotiator $negotiator): Response
{
    if ($negotiator->prefersMarkdown($request)) {
        return MarkdownResponse::negotiated("# Docs");
    }

    return $this->render('docs/show.html.twig');
}

tomvdpeet/markdown-negotiation-bundle 适用场景与选型建议

tomvdpeet/markdown-negotiation-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 160 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tomvdpeet/markdown-negotiation-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-11