Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

KyleAMathews
Copy link
Contributor

Summary

This PR adds content negotiation to documentation routes to serve markdown when AI coding agents and LLMs request it via the Accept header.

Like the brother of Jared who saw things more clearly through simplicity, LLMs can process markdown much more efficiently than HTML - reducing token usage by ~10x.

Changes

  • Added prefersMarkdown() helper function to parse Accept headers with quality values
  • Added ServerRoute handlers to both doc routes:
    • $libraryId/$version.docs.$.tsx
    • $libraryId/$version.docs.framework.$framework.$.tsx
  • Returns raw markdown when Accept: text/markdown or Accept: text/plain is preferred over HTML
  • Added Vary: Accept header to ensure proper caching of both formats

How it works

When a request comes in with an Accept header like:

Accept: text/markdown, text/html;q=0.9

The server will return markdown content instead of rendering the HTML page. This allows tools like Claude Code, Cursor, and other AI agents to fetch cleaner, more parseable documentation.

Testing

Test with:

curl -H "Accept: text/markdown" https://tanstack.com/router/latest/docs/overview

Should return raw markdown instead of HTML.

🤖 Generated with Claude Code

Add content negotiation to doc routes to serve markdown when
Accept: text/markdown or Accept: text/plain is requested.

This allows AI coding agents and LLMs to fetch cleaner markdown
content instead of HTML, reducing token usage by ~10x.

- Add prefersMarkdown() helper to check Accept header
- Add ServerRoute handler to both doc routes
- Include Vary: Accept header for proper caching

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

netlify bot commented Oct 9, 2025

Deploy Preview for tanstack failed. Why did it fail? →

Name Link
🔨 Latest commit 67530f0
🔍 Latest deploy log https://app.netlify.com/projects/tanstack/deploys/68e841b1d5bebf0008e54633

Extract shared utilities to src/utils/docs.ts:
- prefersMarkdown() - Parse Accept header with quality values
- createMarkdownResponse() - Create standardized markdown response

Both doc routes now use these shared functions, eliminating
duplicate code and making maintenance easier.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.