GitHub 0
Skip to content

Installation

Install whoasks, put it in front of an h3, Nitro, Hono or Cloudflare Workers app, and check with curl that Markdown comes back.
pnpm
pnpm add whoasks
npm
npm install whoasks
yarn
yarn add whoasks
bun
bun add whoasks

Requirements and package details:

  • Node 22.12 or later.
  • ESM only.
  • mdream is the only runtime dependency.
  • whoasks/h3 needs 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.
text

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>`,
  ),
);
app.ts

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());
server/middleware/whoasks.ts

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)));
app.ts

No test runs this snippet.

import { whoasks } from "whoasks";

const site = whoasks();

export default {
  fetch: (request: Request, env: { ASSETS: Fetcher }) =>
    site.handle(request, (r) => env.ASSETS.fetch(r)),
};
worker.ts

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.

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),
};
server.ts

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:

Runtimewhoasks/corewhoasks (with mdream)
Node 22.12Must passMust pass
BunMust passReported, not required
Deno 2Must passReported, not required

Replace http://localhost:3000 with your server's address.

  1. curl -i -H 'Accept: text/markdown' http://localhost:3000/docs/guide

    Expected response:

    content-type: text/markdown; charset=utf-8
    vary: Accept
    
    # Guide
    
    Hello
    text
  2. curl http://localhost:3000/docs/guide.md
    curl 'http://localhost:3000/docs/guide?format=md'

    Both print the same Markdown.

  3. curl -i http://localhost:3000/docs/guide

    The page comes back as text/html with vary: Accept.

ImportHolds
whoaskswhoasks with mdream as its converter, mdream, and the seven types
whoasks/corewhoasks with no converter, and the seven types. It has no imports and stays under 10 kB
whoasks/h3middleware

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.