Markdownify¶
Markdownify is a Drupal module that provides a seamless solution for generating Markdown versions of your site's content. Via any of the six supported request patterns, this module enables bots, AI agents, and developers to access a lightweight, Markdown-based representation of your site’s content for easier parsing and consumption.
or a full description of the module, visit the project page.
Submit bug reports and feature suggestions, or track changes in the issue queue.
Table of Contents¶
- Why Markdown?
- Requirements
- Installation — install the module and its conversion library with Composer, enable it, and pick the submodules you need.
- Configuration - The settings form is optional — the module works immediately for nodes and taxonomy terms. Everything you can tune is covered in the Setup Guide.
- How It Works
- How to Access Markdown Versions of Content
- Optional: Enable the Markdownify Path Submodule
- Optional: Enable the Markdownify Views Pages Submodule
- Contributing
- License
- Maintainers
Why Markdown?¶
While modern LLMs can ingest and parse raw HTML, Markdown offers significant advantages:
- Cost Efficiency: AI services charge based on token usage, typically in increments of one million. In our testing, Markdown reduces token count by a * 10:1 ratio* compared to HTML, leading to lower costs.
- Faster Processing: The reduction in token count results in quicker processing of your content in Markdown format.
- Zero Distractions: The Markdown output omits headers, footers, ads, and other irrelevant elements, providing a clean and concise context for AI models.
- Universal Format: Markdown is widely supported and easily understood by AI models, making it the lingua franca for structured text.
Requirements¶
This module requires:
- Drupal Version: 9.x or higher
- PHP Version: 8.0 or higher
How It Works¶
The Markdownify module leverages the power of the League HTML-to-Markdown Library to convert HTML-rendered content into clean Markdown format.
When a request for a .md version of an entity is received, the module:
- Renders the Entity: The module uses the standard Drupal render pipeline to generate the HTML representation of the requested entity.
- Converts HTML to Markdown: Using the
League\HTMLToMarkdown\HtmlConverter, the module processes the HTML output and transforms it into Markdown format. - Delivers Markdown Output: The Markdown version of the content is served to the client, omitting unnecessary elements like headers, footers, or advertisements.
By removing unnecessary elements, the output remains concise and AI-friendly.
How to Access Markdown Versions of Content¶
Once enabled, Markdownify provides six ways to access Markdown-formatted content. With the Markdownify Path submodule enabled, you can also access Markdown content via human-readable path aliases.
Six Ways to Access Markdown Content¶
-
Appending
.mdto the URL Simply append.mdto the entity URL:curl -I https://yourwebsite.com/node/1.md -
Appending
.mdto Path Aliases (viaMarkdownify PathSubmodule) Access Markdown versions of content using the path alias followed by.md:curl -I https://yourwebsite.com/en/articles/sample-article.md -
Using the
/markdownifyPath Prefix Prepend/markdownifyto the URL:curl -I https://yourwebsite.com/markdownify/node/1 -
Using the
_formatQuery Parameter Add_format=markdownto the URL:curl -I "https://yourwebsite.com/node/1?_format=markdown"
See https://www.drupal.org/node/2501221 for more information about the
_format query parameter.
-
Using the
AcceptHeader SpecifyAccept: text/markdownin your request headers:curl -I https://yourwebsite.com/node/1 -H "Accept: text/markdown" -
Using the
Content-TypeHeader SetContent-Type: text/markdownin the request headers:curl -I https://yourwebsite.com/node/1 -H "Content-Type: text/markdown"
Supported Routes¶
| Access Method | Example Usage |
|---|---|
.md extension (Canonical Path) |
/node/1.md |
.md extension (Path Alias) |
/en/articles/sample-article.md |
/markdownify path prefix |
/markdownify/node/1 |
_format query parameter |
/node/1?_format=markdown |
Accept header |
/node/1 (with Accept set) |
Content-Type header |
/node/1 (with Content-Type set) |
Examples¶
Standard HTML Page¶
https://example.com/node/1
Markdown Versions¶
- Using
.mdextension:Using Path Alias:https://yourwebsite.com/node/1.mdhttps://yourwebsite.com/en/articles/sample-article.md - Using
/markdownifypath prefix:https://yourwebsite.com/markdownify/node/1 - Using
_formatparameter:https://yourwebsite.com/node/1?_format=markdown - Using HTTP headers:
Add either
Accept: text/markdownorContent-Type: text/markdownto your requests.
This applies to nodes, taxonomy terms, and other entities that support route handling in Drupal.
Contributing¶
Contributions are welcome! Feel free to submit issues and pull requests on the Markdownify project page.
License¶
Markdownify is open-source and distributed under the GPL-2.0-or-later license.
Maintainers¶
This module is maintained by: