Convert WordPress posts to Markdown with a simple URL pattern
A simple WordPress plugin that lets you view or download any post/page as Markdown by adding /md/ or .md to the URL.
# Clone the repo
git clone https://github.com/ideadude/dot-md.git
# Move to WordPress plugins directory
mv dot-md /path/to/wordpress/wp-content/plugins/
# Activate in WordPress adminAdd /md/ to any post URL:
https://example.com/my-post/ → Original
https://example.com/my-post/md/ → Markdown (displays in browser)
Add .md to any post URL (requires web server configuration):
https://example.com/my-post.md → Downloads markdown file
- Upload to
/wp-content/plugins/dot-md/ - Activate via WordPress admin
/md/endpoint works immediately
To enable .md downloads, add a rewrite rule:
Add before standard WordPress rules:
# Custom rule for .md downloads
RewriteRule ^(.+)\.md$ /$1/md/?download=1 [QSA,L]Add to server block:
rewrite ^/(.+)\.md$ /$1/md/?download=1 last;- 🚀 Zero Config - Works immediately after activation
- 📝 Smart Conversion - Handles headers, lists, links, images, code, tables, blockquotes
- ⚡ Cached - Generated markdown cached for 1 week, auto-refreshed on updates
- 🎯 Two Modes - View in browser or download file
- 🔧 Developer Friendly - Filterable output, clean code
- 📊 Metadata - Includes title, date, author, permalink in every file
- AI Integration: Feed content to Claude, ChatGPT, or other LLMs
- Content Migration: Export to static site generators (Hugo, Jekyll, etc.)
- Documentation: Quick export for developer docs
- Archival: Backup content in portable format
- Cross-platform: Share content in universal format
dotmd_markdown_output - Modify markdown before output
add_filter( 'dotmd_markdown_output', function( $markdown, $post ) {
// Add custom footer
$markdown .= "\n\n---\nGenerated by My Company";
return $markdown;
}, 10, 2 );Markdown is cached using WordPress transients:
- Key pattern:
dotmd_{post_id}_v{version} - Duration: 1 week
- Auto-cleared on: Post update, post deletion
- Detect - WordPress rewrite endpoint catches
/md/in URL - Convert - HTML → Markdown using league/html-to-markdown (namespaced to
DotMD\HtmlToMarkdown) - Cache - Store result in transient for 1 week
- Serve - Output with appropriate headers (inline or attachment)
This plugin extends the base league/html-to-markdown library with custom converters for cleaner, more AI-friendly markdown output:
Strips semantic HTML5 tags while preserving content:
<article>,<header>,<section>,<footer>,<main>,<aside>,<nav><figure>,<figcaption>,<cite>,<span>
Handles additional inline formatting:
<s>,<del>,<strike>→~~strikethrough~~<u>and<mark>→ stripped (no markdown equivalent)
Converts HTML form inputs to markdown equivalents:
<input type="checkbox" checked>→[x](task lists)<input type="checkbox">→[ ](task lists)
Handles collapsible HTML5 details/summary:
<summary>→**bold summary text**<details>→ clean content blocks
Converts embedded iframes to clean links:
<iframe src="URL" title="Title">→[Title](URL)<iframe src="URL">→<URL>(auto-link format)- Especially useful for YouTube, Vimeo, and other video embeds
Registered from base library (was missing):
- Converts HTML tables to markdown table format
Note: These converters extend the base library to better handle WordPress content and modern HTML. This creates a fork from the standard league/html-to-markdown behavior but produces cleaner output for AI consumption and content portability.
| Requirement | Version |
|---|---|
| WordPress | 5.0+ |
| PHP | 7.4+ |
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-thing) - Commit your changes (
git commit -m 'Add new thing') - Push to the branch (
git push origin feature/new-thing) - Open a Pull Request
- Issues: GitHub Issues
- Documentation: See readme.txt for WordPress.org format
- Built with league/html-to-markdown
- Created by @ideadude
GPL v2 or later - License Details
Built for the WordPress and AI communities