Skip to content

WordPress plugin to generate a markdown version of a post when /md/ or .md is appended to the post URL.

Notifications You must be signed in to change notification settings

ideadude/dot-md

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dot MD

Convert WordPress posts to Markdown with a simple URL pattern

WordPress Plugin PHP Version License

A simple WordPress plugin that lets you view or download any post/page as Markdown by adding /md/ or .md to the URL.

Quick Start

# 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 admin

Usage

View in Browser

Add /md/ to any post URL:

https://example.com/my-post/      → Original
https://example.com/my-post/md/   → Markdown (displays in browser)

Download File

Add .md to any post URL (requires web server configuration):

https://example.com/my-post.md    → Downloads markdown file

Installation & Configuration

1. Install Plugin

  • Upload to /wp-content/plugins/dot-md/
  • Activate via WordPress admin
  • /md/ endpoint works immediately

2. Configure Web Server (Optional)

To enable .md downloads, add a rewrite rule:

Apache (.htaccess)

Add before standard WordPress rules:

# Custom rule for .md downloads
RewriteRule ^(.+)\.md$ /$1/md/?download=1 [QSA,L]

Nginx

Add to server block:

rewrite ^/(.+)\.md$ /$1/md/?download=1 last;

Features

  • 🚀 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

Use Cases

  • 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

Developer API

Filters

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 );

Cache Management

Markdown is cached using WordPress transients:

  • Key pattern: dotmd_{post_id}_v{version}
  • Duration: 1 week
  • Auto-cleared on: Post update, post deletion

How It Works

  1. Detect - WordPress rewrite endpoint catches /md/ in URL
  2. Convert - HTML → Markdown using league/html-to-markdown (namespaced to DotMD\HtmlToMarkdown)
  3. Cache - Store result in transient for 1 week
  4. Serve - Output with appropriate headers (inline or attachment)

Custom Converters

This plugin extends the base league/html-to-markdown library with custom converters for cleaner, more AI-friendly markdown output:

SemanticConverter

Strips semantic HTML5 tags while preserving content:

  • <article>, <header>, <section>, <footer>, <main>, <aside>, <nav>
  • <figure>, <figcaption>, <cite>, <span>

InlineFormatConverter

Handles additional inline formatting:

  • <s>, <del>, <strike>~~strikethrough~~
  • <u> and <mark> → stripped (no markdown equivalent)

InputConverter

Converts HTML form inputs to markdown equivalents:

  • <input type="checkbox" checked>[x] (task lists)
  • <input type="checkbox">[ ] (task lists)

DetailsConverter

Handles collapsible HTML5 details/summary:

  • <summary>**bold summary text**
  • <details> → clean content blocks

IframeConverter

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

TableConverter

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.

Requirements

Requirement Version
WordPress 5.0+
PHP 7.4+

Contributing

Contributions are welcome! Feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-thing)
  3. Commit your changes (git commit -m 'Add new thing')
  4. Push to the branch (git push origin feature/new-thing)
  5. Open a Pull Request

Support

Credits

License

GPL v2 or later - License Details


Built for the WordPress and AI communities

About

WordPress plugin to generate a markdown version of a post when /md/ or .md is appended to the post URL.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages