Skip to content

cmd/stripes: render .md files served as text/plain - #46

Merged
achille-roussel merged 1 commit into
mainfrom
fix-render-md-files
Jun 20, 2026
Merged

cmd/stripes: render .md files served as text/plain#46
achille-roussel merged 1 commit into
mainfrom
fix-render-md-files

Conversation

@achille-roussel

Copy link
Copy Markdown
Contributor

Problem

A .md file served by raw.githubusercontent.com rendered as plain text instead of Markdown:

stripes https://raw.githubusercontent.com/GoogleCloudPlatform/knowledge-catalog/main/okf/README.md

GitHub's raw server sends Content-Type: text/plain; charset=utf-8 for every file, and stripes used that server hint verbatim — before the filename/extension cascade ever ran. So the .md extension never got a chance to route to the Markdown renderer.

Fix

In renderOne (cmd/stripes/main.go), treat a text/plain hint as weak. After picking up the server hint, if its media type parses to text/plain, run stripes.Detect(name, peek) and prefer the result when it's more specific.

  • Uses mime.ParseMediaType, so text/plain; charset=utf-8 is matched (the actual GitHub case), not just bare text/plain.
  • Only text/plain hints are reconsidered — any other server content-type (JSON, protobuf, etc.) is untouched.
  • The extension is just a candidate: Detect also weighs content sniffing, so a genuine .txt detects back to text/plain and stays plain.

Tests

Added cmd/stripes/render_test.go covering .md over text/plain; charset=utf-8, .md over bare text/plain, and .txt staying plain. Verified against the original URL — it now renders as Markdown — and the full suite + go vet pass.

🤖 Generated with Claude Code

Servers like raw.githubusercontent.com serve every file as
"text/plain; charset=utf-8", so a .md URL was rendered as plain text
because the server hint won outright over filename detection.

Treat a text/plain hint as weak: when the server says text/plain, run
the filename/sniff detection and prefer its result if it's more
specific. The media type is parsed via mime.ParseMediaType so a charset
parameter still matches. Genuine .txt files detect back to text/plain
and stay plain.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@achille-roussel
achille-roussel merged commit 5f9039e into main Jun 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant