Every Post, Now in Markdown

By
Tech · Web

Markdown logo on a plain white sheet over a technical diagram-like background

Every post on this site can now be read as plain Markdown.

Add .md to the end of any post URL and you get the text I actually wrote: no HTML, no CSS, no JavaScript, no theme. Just words, links, images, and code blocks, readable in any text editor or terminal. Clients that ask for Markdown in their Accept header get it at the normal URL, too.

I’ve written every post here in Markdown since Reblog 3.0. But readers never saw that text. They got it rebuilt as a fairly involved HTML page with custom elements, utility classes, dynamic @include content, and script-driven extras. That’s fine for a browser. It’s overkill for anything else, and plain text will outlast any of that scaffolding.

This post documents what changed and why. Like most of my site posts, it’s mostly for future me.

Why Bother?

There are three reasons.

Longevity. HTML templates, CSS, and JavaScript break, change, or get thrown out over time. I’ve rebuilt this site three times in 25 years, and every migration taught me how hard it is to pull clean content back out of old markup. Markdown is the content with nothing wrapped around it. If the rest of the stack disappears tomorrow, the .md files still read fine.

Agents and tools. More software reads the web without rendering it: AI assistants, research tools, command-line readers, and feed-style aggregators. A common convention is emerging for these clients. They send Accept: text/markdown, or they look for a .md alternate, and they get clean text instead of scraping a page meant for eyeballs. Converting a rendered page back to Markdown is lossy and wasteful when I already have the source.

Honesty about the source. The stored text is Markdown. Serving it directly is simpler than any conversion pipeline.

Three Ways In

  1. The .md suffix. /post/<slug>.md returns the post as Markdown. This post is at /post/every-post-now-in-markdown.md.
  2. Content negotiation. Request the normal post URL with Accept: text/markdown and you get the same thing.
  3. Discovery. Every published post’s HTML <head> carries a link to its Markdown alternate:
<link rel="alternate" type="text/markdown" href="/post/every-post-now-in-markdown.md">

The RSS feed does the same for each item, so feed readers and agents can find the Markdown without loading the page first:

<atom:link href="https://morgandavis.net/post/every-post-now-in-markdown.md" rel="alternate" type="text/markdown"/>

From a terminal:

# Explicit .md URL
curl -A 'Mozilla/5.0' https://morgandavis.net/post/every-post-now-in-markdown.md

# Same post, negotiated
curl -A 'Mozilla/5.0' -H 'Accept: text/markdown' https://morgandavis.net/post/every-post-now-in-markdown

The -A is there because the site’s existing bot filters apply to Markdown requests exactly as they do to HTML. A bare curl user agent gets turned away either way. I didn’t carve out an exemption.

What You Get

The response is text/markdown; charset=utf-8; variant=GFM, meaning GitHub Flavored Markdown. It starts with YAML front matter, followed by the post body:

---
title: "Every Post, Now in Markdown"
author: "Morgan Davis"
pubDate: "Fri, 04 Dec 2026 12:00:00 +0000"
description: "Every post on this site can now be read as plain Markdown..."
link: "https://morgandavis.net/post/every-post-now-in-markdown"
image: "/content/uploads/2026/12/every-post-now-in-markdown.webp"
categories: ["Tech", "Web"]
urlNext: "/post/why-freebsd-packages-take-so-long.md"
---
  • pubDate uses the same RFC 822 format as the RSS feed.
  • updated appears only when the page’s dateline would show it, which is more than a week after publishing and only for body edits.
  • link is the canonical HTML page, which is also sent as a Link: <...>; rel="canonical" response header.
  • image is the same image the post index uses as its thumbnail.
  • urlPrev and urlNext point to the neighboring posts’ .md URLs, so a reader can walk the whole blog without touching HTML.

Empty fields are left out.

The body is my source text, nearly verbatim. Typography stays as typed (--, straight quotes), relative links stay relative, and fenced code blocks pass through untouched. Footnotes, tables, task lists, and abbreviations are already valid GFM, so they need no work. Only constructs that exist solely for this site get converted or removed:

In the source In the .md
{.class width="..."} attribute blocks on images, links, headings removed
{{div class="grid x2"}} layout wrappers unwrapped; content kept
{{private}} blocks gone, always
Images marked .list-only or .hide removed
YouTube .video shortcodes [Video: title](https://www.youtube.com/watch?v=...)
@include links and fenced @include lines removed (an include URL might carry an access key)
<br> two-space hard break; -- inside table cells
<style>, <script>, HTML comments removed
Any other inline HTML tag tag dropped, text kept
## Heading {#custom-id} ## Heading, with in-post ](#custom-id) links rewritten to the automatic ID

Reading a .md URL doesn’t count as a view. My stats track people reading pages, and a Markdown fetch is almost always a machine.

Filter, Don’t Convert

I considered three approaches:

  1. Render the HTML, then convert it back to Markdown. Some CDNs do this for you. It’s normalized, but it throws away the text I actually wrote. It’s lossy on tables and footnotes, and it needs a large converter. No.
  2. Serve the raw source and call it Markdown Extra. My attribute blocks and {{div}} wrappers aren’t really Extra. Most consumers would choke on them or render them as literal text. No.
  3. Filter at output time. The stored source remains the single source of truth, and a fence-aware filter strips or converts the site-specific parts on the way out. Yes.

I also looked for an official spec that already covers custom block syntax, so I could adopt it instead of filtering. I checked the IANA Markdown variants registry (RFC 7763 and RFC 7764) and the CommonMark generic-directives proposal, which still hasn’t been adopted. None of them fit. So “use the standard” came down to using GFM features that exist and filtering out the rest.

The filter lives in a new MarkdownExport class. The HTML path didn’t change. Before shipping, I rendered every post with the old and new code and diffed the results. The only differences were the intended ones.

Cleaning Up the Source First

Filtering works better when there’s less to filter, so the first phase moved the stored content closer to plain Markdown wherever that cost nothing in the rendered page. A one-time script handled this. It defaulted to a dry run that printed a diff for each post, never touched anything inside code fences, and didn’t change any post’s “updated” date, because cleanup isn’t authorship. I ran it on the dev database, checked the dev site, then ran it on production: 103 posts.

Root-Relative URLs

Many old posts used document-relative paths like ](content/uploads/...). In HTML these resolve against the site root because of the page’s <base> tag. A Markdown reader resolves them against the .md URL instead, and that breaks them. They’re all root-relative now (](/content/uploads/...)).

Automatic Heading IDs

Headings now get GitHub-style IDs automatically: lowercase, punctuation removed, spaces turned into hyphens, and -1, -2 appended to duplicates. That made most of my hand-written {#id} attributes redundant, so the script removed them. An explicit ID still wins when I want one. The .md exporter uses the same slug function, so in-post anchor links work in both formats.

One Vocabulary of Utility Classes

Over the years I’d accumulated a pile of one-off image classes and inline styles. I replaced them with a small, memorable set, scoped to post bodies so they can’t collide with site UI:

Purpose Classes
Width .w20 .w25 .w33 .w50 .w75
Break out of the column .hero .wide .full
Placement .left .right (float), .center
Inline icon .icon
Boxed content .panel
Effects .rounded .invert
Spacing .pad
Behavior .no-hero .new-tab .list-image .list-only .hide

The old names shipped as aliases first, then the content was migrated, then the aliases were removed. Nothing broke along the way.

.list-only Images

Some posts had an image commented out of the body so it would show up only as the post’s thumbnail in the index. That was a hack. Now .list-only says it directly: the thumbnail picker sees the image, but the article page, RSS feed, and .md never do.

{{private}} Blocks

Sometimes I want notes in a post that only I can see when I’m logged in, like commands with real hostnames or reminders to myself. That used to be a CSS trick that kept the text in the page, just hidden. Not good enough. Now there’s a real block:

{{private}}
Anything here, including Markdown, is visible only in admin mode.
{{/private}}

Private text is removed from the source before parsing, in one place that everything goes through: the post page, RSS, thumbnails, meta descriptions, search, and the .md output. Search uses a small SQLite function to match against the public text only, and only for posts that actually contain a private block. An unclosed {{private}} hides the rest of the post. A typo should never publish something private.

A “Private” category works at the post level: such posts are unlisted. They don’t appear in the index, search, category pages, RSS, or prev/next links, but a direct link or share link still works. Unlisted, not secret.

A Reference Post for Me

An old Markdown test draft became my authoring reference: every utility class, every special construct, and a live example of each. It stays unpublished. It’s a cheat sheet, not an article.

Negotiation Details

The extensionless post URL has to keep serving HTML to every browser, so the Accept rules are deliberately strict:

  • Markdown is served only when text/markdown is listed explicitly with q > 0.
  • Its q must be at least that of text/html (or text/*, or */* if HTML isn’t listed).
  • Wildcards alone never select Markdown, so browsers always get HTML.
  • A tie goes to Markdown. Only a client that can read it would list it.

Negotiated responses add Content-Location: /post/<slug>.md, and extensionless post URLs send Vary: Accept (including on 304 Not Modified), so caches keep the two formats apart.

Bots and AI Crawlers

Making the text easy for machines to read raises the question of which machines. My position is that legitimate AI training is fine as long as it doesn’t load the server or cause headaches. So robots.txt now lets the major, well-behaved AI crawlers fall under the general rule. Crawlers with a history of ignoring robots.txt or hammering servers stay blocked, as does Common Crawl’s CCBot. The existing NGINX and PHP user-agent filtering is unchanged and applies to .md the same as everything else.

I skipped llms.txt. The idea is fine, but the spec is half-baked, and a rel="alternate" link plus content negotiation already do the job using plain HTTP.

Explore