vlt / affordances
  • Quickstart
  • Concepts
  • Guides
  • Reference
  • Overview
  • Setup
  • Markers
  • What gets converted
  • Caching and privacy
  • llms.txt and llms-full
  • htmlToMarkdown
  1. Plugins
  2. /
  3. Markdown
  4. /
  5. htmlToMarkdown

htmlToMarkdown

The converter on its own, with no React or Next.js dependency.

htmlToMarkdown from @affordances/md is the converter the route handler uses. Give it any HTML document:

TypeScript
import { htmlToMarkdown } from '@affordances/md'

const html = await (await fetch('https://example.com/post')).text()
const { markdown, title, url, tokens } = htmlToMarkdown(html, { url: 'https://example.com/post' })
OptionDefaultDescription
urlnoneBase for absolute links and images, usually the page's URL
extract'auto''auto': markers, then <main>, then the body minus chrome; 'none': the whole body; or a function of the tree
frontmattertruePrepend YAML frontmatter from the page's metadata
jsonLdtrueAppend the page's JSON-LD as fenced JSON
handlersnonePer-element overrides, as hast-util-to-mdast handlers

It returns the Markdown, the page's title, its canonical url (or the one you passed), and tokens, an estimate of the Markdown's length in tokens (characters divided by four).


Previousllms.txt and llms-fullNextOverview
Edit this page

Make your app agent-operable

Give every page a graph and every server action an agent path: HTTP, WebMCP, and MCP, with the same session and the same checks. One command sets it up.

Read the quickstart