zeix/craft-marked-down
Composer 安装命令:
composer require zeix/craft-marked-down
包简介
Marked Down serves Markdown to AI crawlers, command-line tools, and APIs while browsers get HTML. Zero-config per-section setup, automatic AI bot detection, .md URL suffix, /llms.txt, YAML front matter, and dedicated Markdown templates — out of the box.
README 文档
README
A Craft CMS plugin that intelligently serves Markdown content to AI tools, APIs, and command-line clients, while browsers continue to receive HTML.
Why Marked Down?
The Problem
Modern websites are designed for humans viewing them in browsers—complete with navigation menus, sidebars, footers, analytics scripts, and styling. But when AI tools like ChatGPT, Claude scrape your site, they get the entire HTML payload.
Result: Wasted tokens, confused AI models, cluttered API responses, and poor developer experience.
The Solution
Marked Down uses HTTP content negotiation to serve clean, semantic Markdown when appropriate:
Benefits:
- 🎯 10-15x smaller responses - Markdown is dramatically more compact than HTML
- 🤖 Better AI understanding - LLMs process clean Markdown more effectively than noisy HTML
- 🔌 Standard HTTP - Uses the
Accept: text/markdownheader (proper content negotiation) - 🌐 Zero impact on browsers - Your website looks and works exactly the same for human visitors
- ⚡ Built-in caching - Fast responses with configurable cache duration
- 🎨 Smart extraction - Automatically finds and converts your main content, stripping navigation and boilerplate
Real-World Use Cases
- Documentation sites - Let AI assistants cite your docs accurately
- Technical blogs - Make your content easily consumable by AI tools
- API documentation - Serve both human-readable HTML and machine-readable Markdown
- Content APIs - Provide Markdown output without building separate endpoints
- AI training - Offer clean content for AI model training datasets
- Command-line tools - Enable CLI users to read your content in their terminal
Installation
Standard Installation
composer require zeix/craft-marked-down ./craft plugin/install marked-down
DDEV Installation
If you're using DDEV for local development:
ddev composer require zeix/craft-marked-down ddev craft plugin/install marked-down
How It Works
Marked Down serves the same entry as Markdown when a client asks for it, and as normal HTML otherwise. A request is served Markdown when any of these is true:
.mdURL suffix — append.mdto any entry URL (e.g./blog/my-article.md).Accept: text/markdownheader — standard HTTP content negotiation.- AI bot User-Agent — the request comes from a known crawler (GPTBot, ClaudeBot, PerplexityBot, and others; configurable).
Everything else gets HTML, untouched. On HTML pages the plugin also injects a <link rel="alternate" type="text/markdown"> tag so Markdown-aware clients can discover the .md version, and Markdown responses carry X-Robots-Tag: noindex so they don't compete with your canonical HTML in search.
Quick Test
# .md suffix curl https://yoursite.com/blog/my-article.md # Accept header curl -H "Accept: text/markdown" https://yoursite.com/blog/my-article # As an AI bot curl -A "GPTBot/1.0" https://yoursite.com/blog/my-article # Normal browser request — unchanged HTML curl https://yoursite.com/blog/my-article
Each Markdown response is prefixed with YAML front matter (title, date, author, canonical URL, section) and has navigation, headers, footers, and scripts stripped out.
Configuration
Plugin Settings
Navigate to Settings → Plugins → Marked Down:
- Enable Marked Down: Toggle the plugin on/off
- Excluded Paths: Paths that always serve HTML (e.g.,
/admin,/actions/*) - Include Only Paths: (Optional) Restrict Markdown to specific paths. Leave empty to allow all paths — if set, only matching paths serve Markdown.
- AI Bot User-Agents: The crawler patterns that trigger Markdown (matched case-insensitively against the User-Agent).
- Caching: Enable caching and set cache duration (default: 24 hours)
Per-section settings
Each section can be configured independently (stored in project config, keyed by section UID so it survives renames and syncs across environments):
- Enabled: Serve Markdown for this section at all (default: on).
- AI-bots-only: Serve Markdown only to detected AI bots. Humans hitting the
.mdURL or sendingAccept: text/markdownstill get HTML — useful when you want crawlers fed but the.mdURLs kept out of public reach. - Dedicated template: Point a section at a Twig template that outputs raw Markdown directly, bypassing HTML→Markdown conversion entirely. Receives the
entryvariable. - Front matter: Toggle the YAML front-matter block per section.
llms.txt
Marked Down publishes a /llms.txt site index following the llms.txt spec — a per-section list of recent entries linking to their .md URLs, so AI tools can discover your Markdown content from one file. Configure the number of entries per section in the plugin settings (llmsTxtEntriesPerSection, default 20).
Config File
Create config/marked-down.php to exclude specific CSS selectors from Markdown output:
<?php return [ // Global exclusions - applied to all pages 'globalExclusions' => [ '.sidebar', '#comments', '.social-share', 'nav.secondary', ], // Template-specific exclusions - applied only to specific templates 'templateExclusions' => [ 'blog/_entry' => ['.author-bio', '#related-posts'], 'news/_entry' => ['#comments', '.share-buttons'], '_layouts/article' => ['.sidebar'], ], ];
How it works:
- Global exclusions are applied to all pages
- Template exclusions are only applied when a specific template is rendered
- Template paths should match your template file structure (e.g.,
blog/_entryfortemplates/blog/_entry.twig) - Both
.twigextension and without work (e.g.,blog/_entryorblog/_entry.twig)
Supported CSS Selectors:
#id- ID selectors.class- Class selectorselement- Element selectors (e.g.,nav,aside)element#id- Combined element and IDelement.class- Combined element and class
Note: Complex selectors like descendant selectors (.parent .child) or pseudo-classes (:hover) are not currently supported. See config.example.php for more details.
Caching & front matter
- Body conversion is cached (keyed per URL,
cacheDurationdefault 24h) and automatically invalidated when the entry is saved or deleted. Editing an entry refreshes its Markdown immediately; editing the Twig template does not fire a save, so runmarked-down/default/cache-clear(or re-save the entry) to pick up template changes. - YAML front matter is generated fresh on every request (it is not cached), so title/date/author always reflect the entry's current state.
- The
authorfield is included only when the entry has an author assigned — empty fields are omitted to keep the front matter valid and clean.
CLI Commands
Marked Down includes powerful command-line tools for testing and debugging:
Test Conversion
Test the markdown conversion with sample HTML to verify everything is working:
./craft marked-down/default/test-conversion
# or with DDEV
ddev craft marked-down/default/test-conversion
This runs a comprehensive test that validates headings, bold, italic, links, images, lists, and tables.
Convert URL
Fetch and convert any URL to markdown:
./craft marked-down/default/convert https://example.com
# or with DDEV
ddev craft marked-down/default/convert https://example.com
Add --verbose to see the original HTML:
./craft marked-down/default/convert https://example.com --verbose
Clear Cache
Clear all cached markdown conversions:
./craft marked-down/default/cache-clear
# or with DDEV
ddev craft marked-down/default/cache-clear
Plugin Info
View current plugin configuration and status:
./craft marked-down
# or with DDEV
ddev craft marked-down
Shows enabled status, cache settings, excluded/included paths, and config file location.
Requirements
- Craft CMS 5.8.0+
- PHP 8.2+
Credits
Marked Down is built with:
- league/html-to-markdown - The excellent HTML to Markdown conversion library by The PHP League
License
MIT
zeix/craft-marked-down 适用场景与选型建议
zeix/craft-marked-down 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 4, 最近一次更新时间为 2026 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「markdown」 「content-negotiation」 「Craft」 「craftcms」 「craft-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zeix/craft-marked-down 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zeix/craft-marked-down 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zeix/craft-marked-down 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Laminas Module providing content-negotiation features
Adds more BBCode
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: mit
- 更新时间: 2026-02-04