Skip to content

Getting Started

Overview

Welcome to webforai, an library designed to convert HTML to Markdown with simple utilities. Whether you're working in a browser, Node.js, or even on Cloudflare Workers, webforai is your go-to tool for bridging between web and LLMs.

Installation

npm
npm i webforai

Quick Start (CLI)

You can convert HTML to Markdown with the following command.

$ npx webforai@latest https://www.npmjs.com/package/webforai
 
  webforai CLI version 1.6.3

  Select loader:
  fetch # fetch(default) or playwright

  Enter the output file path:
  npmjs-package-webforai.md # default is `{escaped-url}.md`

  Select processing mode:
  default # default or ai mode. ai mode is remove imapges, links, and so on.

  Content loaded!

  Done! Markdown saved to npmjs-package-webforai.md

Quick Start (Library)

Load HTML with utilities

Firstly, load HTML using the loadHtml utility. Using this function, you can get HTML from a URL in a simple way. It supports versions for fetch, Playwright, and Puppeteer.

fetch
import { loadHtml } from "webforai/loaders/fetch"; 
 
// Load html from url
const url = "https://www.npmjs.com/package/webforai";
const html = await loadHtml(url); 

Convert HTML to Markdown

Finally, convert HTML to Markdown with the htmlToMarkdown function.

import { htmlToMarkdown } from "webforai"; 
import { loadHtml } from "webforai/loaders/fetch";
 
// Load html from url
const url = "https://www.npmjs.com/package/webforai";
const html = await loadHtml(url); 
 
const markdown = htmlToMarkdown(html);