Next.js
Next.js Pages Router
Add Accept Markdown support to Pages Router sites with a generated API route.
Pages Router projects are supported with pages/ or src/pages/.
Install
npx --yes accept-md@latest init
pnpm install
The CLI creates pages/api/accept-md/index.js or .ts and configures Markdown requests to reach it.
How requests flow
- A client requests
/some-pagewithAccept: text/markdown. - Next.js routes that request to the accept-md handler.
- The handler fetches the HTML version of
/some-page. - The runtime converts HTML to Markdown and returns it.
Normal browser requests continue through the existing Pages Router page.
JavaScript compatibility
Generated handler content is plain JavaScript-compatible. If your project has tsconfig.json, init may write .ts; otherwise it writes .js.
Do not convert generated user-facing handlers to TypeScript-only syntax if your app is JavaScript.
Verify
curl -s -H "Accept: text/markdown" http://localhost:3000/about
If the response is HTML, run:
npx accept-md doctor