npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

hono-auto-md

v0.1.2

Published

Hono middleware that serves Markdown responses to AI clients by converting HTML via webforai.

Readme

hono-auto-md

Hono middleware that converts HTML responses into Markdown when the incoming request is likely made by an AI agent. It relies on webforai so language models receive content that is easier to consume while browsers keep getting HTML.

Motivation

  • Detect AI-oriented requests by inspecting headers without touching your existing handlers.
  • Reuse the same HTML templates for humans while serving Markdown to crawlers and chat assistants.
  • Add the behaviour as a single middleware that clones the downstream response and swaps in Markdown.

Ultra Quick Start

Just install the package and add the middleware to your Hono app:

npm install hono hono-auto-md

Then:

import { Hono } from 'hono'
import { autoMarkdown } from 'hono-auto-md'

const app = new Hono()

app.use('*', autoMarkdown())

app.get('/', (c) =>
  c.html(`
    <main>
      <h1>Hello!</h1>
      <p>This page will be converted to Markdown for AI agents.</p>
    </main>
  `),
)

export default app

A regular browser hitting / receives HTML. When a caller with headers that look like Claude's code browser visits the same route, the response is converted to Markdown and the middleware adds X-Hono-Auto-Md: TRUE.

Options

app.use('*', autoMarkdown({
  detect: [{ header: 'user-agent', includes: ['my-ai-client'] }],
  htmlToMarkdown: (html) => html,
  allowedContentTypes: ['text/html', 'application/xhtml+xml'],
  responseContentType: 'text/markdown; charset=utf-8',
}))
  • detect: Either a custom (request) => boolean | Promise<boolean> or an array of HeaderMatcher objects (see below). When omitted, CLAUDE_CODE_HEADER_MATCHER is used.
  • htmlToMarkdown: Pass options for webforai's htmlToMarkdown (the middleware sets baseUrl automatically) or provide your own conversion function.
  • allowedContentTypes: Only responses whose Content-Type matches one of these strings are converted. Defaults to text/html and application/xhtml+xml.
  • responseContentType: Header value applied to converted responses. Defaults to text/markdown; charset=utf-8.

Header matchers

A matcher is an object with a header plus optional equals, includes, and matches arrays. The middleware lowercases the header value before comparing.

import type { HeaderMatcher } from 'hono-auto-md'

const matchers: HeaderMatcher[] = [
  { header: 'user-agent', includes: ['claude-user'] },
  { header: 'x-custom-client', equals: ['bot'] },
]

Providing these matchers through the detect option makes the middleware convert responses whenever any matcher hits.

Built-in helpers

The entry point re-exports the pieces you may want to use directly:

  • CLAUDE_CODE_HEADER_MATCHER: Default array of matchers that recognises Claude's code browsing agent.
  • DEFAULT_CONTENT_TYPES: The built-in allowlist for HTML-like responses.
  • MARKDOWN_CONTENT_TYPE: The default Markdown content type string.
  • resolveBaseUrl(url: string): Helper that safely turns a request URL into an absolute base URL for webforai.

Detection details

With no options the middleware uses CLAUDE_CODE_HEADER_MATCHER, which currently looks for user-agent values containing Claude-User. You can swap this out for your own heuristics or an explicit detection function. Responses that already declare a Markdown content type are skipped.

Development

npm install
npm run build
npm run test

Tests run on Vitest. The compiled output lives in dist/ and is published automatically by npm's default files list.