copy2llm-core
v0.2.0
Published
Turn a live DOM into clean Markdown.
Maintainers
Readme
copy2llm-core
The extraction engine behind copy2llm — turns a live DOM into clean Markdown. Pure and framework-agnostic: DOM in, Markdown out, no UI, no network.
npm i copy2llm-coreimport { extract } from "copy2llm-core";
const { markdown, title, url } = extract(document, {
content: "main", // optional CSS selector for the content root; defaults to auto-detect
header: true, // prepend "# {title}\n\n> Source: {url}" (default true)
});interface ExtractResult { markdown: string; title: string; url: string }How it works
Runs on a clone of the page (never mutates the input document):
- Pick the content root — author selector → Readability auto-detect →
<main>/<article>/<body>fallback. - Promote lazy images (
data-src/srcset→src), normalize ragged tables, absolutize relative URLs. - Convert HTML → Markdown via Turndown + GFM, with token-bomb guards (giant
data:URIs) and fence-aware whitespace cleanup. - Prepend the title + source header.
License
MIT
