Teaches the agent the webforai CLI: read any URL or HTML file as clean Markdown, batch-convert URLs, crawl a docs site into Markdown files and llms.txt, and handle JavaScript-heavy or bot-protected pages through the hosted API.
Any HTML to the cleanest Markdown, for humans and AI agents.
Half as many lost pages · 98% of code blocks kept · Half the tokens for agents · Pure TypeScript
Reader mode extracts the main content of a page, like Mozilla Readability, and loses the
page about half as often as the extractors we compared it with. Agent mode adds only the
links an AI agent needs to explore the site, for about half the tokens of converting the whole
page. Both are measured against other converters below.
import { htmlToMarkdown, presetExtractors } from "webforai";
const url = "https://vite.dev/guide/env-and-mode";
const html = await (await fetch(url)).text();
const markdown = htmlToMarkdown(html, { url }); // Reader mode: the main content
const forAgents = htmlToMarkdown(html, { url, extractors: presetExtractors("agent") }); // Agent mode: + the links
What you get — forAgents for that page, abridged
# Env Variables and Modes
Vite exposes certain constants under the special `import.meta.env` object. These constants are
defined as global variables during dev and statically replaced at build time to make tree-shaking
effective.
```js
if (import.meta.env.DEV) {
// code inside here will be tree-shaken in production builds
console.log('Dev mode')
}
```
## Built-in Constants
- **`import.meta.env.MODE`**: {string} the [mode](#modes) the app is running in.
- **`import.meta.env.BASE_URL`**: {string} the base url the app is being served from. …
…
## Links
### Pagination
- [Previous page Deploying a Static Site](https://vite.dev/guide/static-deploy)
- [Next page Server-Side Rendering (SSR)](https://vite.dev/guide/ssr)
### Section navigation
- [Getting Started](https://vite.dev/guide/)
- [Features](https://vite.dev/guide/features)
- [Building for Production](https://vite.dev/guide/build)
- …
Reader mode (default) returns the article alone, up to ## Links: for reading, summarising,
RAG and embeddings.
Agent mode adds the ## Links section — related, pagination, section and site navigation,
breadcrumbs — so an agent can decide which page to open next.
The Markdown reads as the page does: code blocks keep their lines and language, tables stay GFM
tables, notes and warnings become block quotes, links are absolute, KaTeX and MathJax become
LaTeX, and lazy-loaded images come through.
Pages that hide their content from a plain fetch still convert: forum threads shipped inside
<noscript>, and the parts Next.js or GitBook stream after the page's shell.
Page metadata (title, author, published, …) comes from htmlToMarkdownWithMetadata or as YAML
front matter with frontmatter: true.
The snippet runs as-is in Node.js, Cloudflare Workers and browsers: the library uses no Node.js
built-ins and fetches nothing itself. Browser loaders (Playwright, Puppeteer) are optional.