cmd/stripes: render .md files served as text/plain - #46
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A
.mdfile served byraw.githubusercontent.comrendered as plain text instead of Markdown:GitHub's raw server sends
Content-Type: text/plain; charset=utf-8for every file, andstripesused that server hint verbatim — before the filename/extension cascade ever ran. So the.mdextension never got a chance to route to the Markdown renderer.Fix
In
renderOne(cmd/stripes/main.go), treat atext/plainhint as weak. After picking up the server hint, if its media type parses totext/plain, runstripes.Detect(name, peek)and prefer the result when it's more specific.mime.ParseMediaType, sotext/plain; charset=utf-8is matched (the actual GitHub case), not just baretext/plain.text/plainhints are reconsidered — any other server content-type (JSON, protobuf, etc.) is untouched.Detectalso weighs content sniffing, so a genuine.txtdetects back totext/plainand stays plain.Tests
Added
cmd/stripes/render_test.gocovering.mdovertext/plain; charset=utf-8,.mdover baretext/plain, and.txtstaying plain. Verified against the original URL — it now renders as Markdown — and the full suite +go vetpass.🤖 Generated with Claude Code