pnpm add whoasksnpm install whoasksyarn add whoasksbun add whoasksRequirements and package details:
- Node 22.12 or later.
- ESM only.
mdreamis the only runtime dependency.whoasks/h3needs h3 2.0.8 or later. h3 is an optional peer dependency, so install it only if you use that entry.
Ask your coding agent to add it
Add whoasks to this app, following https://whoasks.loadsheet.dev/guide/installation.
Put site.handle in front of the app so its HTML pages also answer as Markdown, and call site.respond in routes that return data.
Then run curl three times against one page: with -H 'Accept: text/markdown', with the .md twin URL, and with no header. Check the Content-Type and Vary of each.Put it in front of your app
Section titled "Put it in front of your app"site.handle(request, next) has the shape of fetch. It takes a Web Request and a function that returns the app's Response, so every runtime below is the same call.
import { H3, defineHandler, html } from "h3";
import { whoasks } from "whoasks";
import { middleware } from "whoasks/h3";
const site = whoasks();
export const app: H3 = new H3().use(middleware(site));
app.get(
"/docs/guide",
defineHandler(
() =>
html`<main>
<h1>Guide</h1>
<p>Hello</p>
</main>`,
),
);middleware(site) passes event.req to handle.
For a twin URL or ?format= request, it sends the canonical URL through the app again from the top. Your /docs/guide route answers /docs/guide.md with no extra route.
A real .md route in the app, such as /notes.md, is still served as the app sends it.
import { whoasks } from "whoasks";
import { middleware } from "whoasks/h3";
export default middleware(whoasks());Nitro v3 runs on h3 v2, so this should work. No test runs it and we did not try it.
import { Hono } from "hono";
import { whoasks } from "whoasks";
const site = whoasks();
const routes = new Hono(); // your routes
const app = new Hono();
app.all("*", (c) => site.handle(c.req.raw, (request) => routes.fetch(request)));No test runs this snippet.
Cloudflare Workers
Section titled "Cloudflare Workers"import { whoasks } from "whoasks";
const site = whoasks();
export default {
fetch: (request: Request, env: { ASSETS: Fetcher }) =>
site.handle(request, (r) => env.ASSETS.fetch(r)),
};A test bundles whoasks for workerd with no Node builtin, runs it in Miniflare, and gets Markdown for Accept: text/markdown.
Under the workerd and edge-light export conditions, mdream uses a wasm build, so the bundle carries a .wasm file.
The test serves a page from the Worker itself. No test runs this snippet with an ASSETS binding.
Any fetch handler
Section titled "Any fetch handler"import { whoasks } from "whoasks";
const site = whoasks();
// Stands for your app: any function from a Request to a Response.
const app = (request: Request): Response =>
new Response("<main><h1>Guide</h1><p>Hello</p></main>", {
headers: { "content-type": "text/html; charset=utf-8" },
});
export default {
fetch: (request: Request): Promise<Response> => site.handle(request, app),
};next may return a Response or a promise of one.
CI installs the packed package and runs it on three runtimes. CI reports whether whoasks with mdream loads on Bun and Deno without requiring it to pass there:
| Runtime | whoasks/core | whoasks (with mdream) |
|---|---|---|
| Node 22.12 | Must pass | Must pass |
| Bun | Must pass | Reported, not required |
| Deno 2 | Must pass | Reported, not required |
Check it
Section titled "Check it"Replace http://localhost:3000 with your server's address.
Ask for Markdown
Section titled "Ask for Markdown"curl -i -H 'Accept: text/markdown' http://localhost:3000/docs/guideExpected response:
content-type: text/markdown; charset=utf-8 vary: Accept # Guide HelloAsk by URL
Section titled "Ask by URL"curl http://localhost:3000/docs/guide.md curl 'http://localhost:3000/docs/guide?format=md'Both print the same Markdown.
Check that people still get HTML
Section titled "Check that people still get HTML"curl -i http://localhost:3000/docs/guideThe page comes back as
text/htmlwithvary: Accept.
Entries
Section titled "Entries"| Import | Holds |
|---|---|
whoasks | whoasks with mdream as its converter, mdream, and the seven types |
whoasks/core | whoasks with no converter, and the seven types. It has no imports and stays under 10 kB |
whoasks/h3 | middleware |
Use whoasks/core to keep mdream out of a bundle. See Without mdream.
Read Pages for what handle does with each request. Read API routes for routes that return data.