/** * get_web_source: read a public web page (a blog post, newsletter or club or * vendor article) as text, with its Wayback Machine snapshots so a citation * can point at a fixed copy. * * Limits: * - Only public http(s) addresses. Names that resolve to loopback, private or * link-local addresses are refused, so a page cannot steer the tool at a * service on the user's machine or network. * - When a site answers with a bot check (Cloudflare and similar), the tool * stops. It never tries to get past one. * - It does not ask the Wayback Machine to save a page; it only reads what is * there and gives the save link. */ import { parseHTML } from "linkedom"; import { type PaperContext, type ServiceLog } from "./core.js"; import { type Section } from "./text.js"; export type Lookup = (host: string) => Promise; /** Throws when the URL is not a public http(s) address. */ export declare function checkPublicUrl(raw: string, lookup?: Lookup): Promise; export declare function isBotChallenge(status: number, headers: Headers, body: string): boolean; export type FetchedPage = { url: string; status: number; contentType: string; bytes: Uint8Array; }; export declare class BotChallengeError extends Error { } /** GET with redirects followed by hand, so every hop is checked against the address rules. */ export declare function fetchPage(ctx: PaperContext, start: URL, lookup?: Lookup): Promise; export type Snapshot = { timestamp: string; url: string; }; export type Snapshots = { earliest?: Snapshot; latest?: Snapshot; }; export declare function snapshotDate(timestamp: string): string; /** The earliest and latest Wayback snapshots of a URL. */ export declare function waybackSnapshots(ctx: PaperContext, url: string): Promise; type Doc = ReturnType["document"]; export type WebPage = { title?: string; author?: string; published?: string; modified?: string; siteName?: string; canonical?: string; licence?: string; description?: string; sections: Section[]; text: string; }; /** * Replace each MathML formula with one text form. LaTeXML pages (arXiv HTML) * carry every formula twice, as rendered MathML and as a LaTeX annotation, so * their text read "13×1013\times 10" and a quote with maths in it could not * match. A simple formula becomes its rendered text ("13×10", "M=192"), which * is what a reader quotes; one with subscripts, fractions and the like * becomes its LaTeX source as inline code, which keeps its structure. */ export declare function flattenMath(document: Doc): void; export declare function extractPage(html: string, pageUrl: string): WebPage; /** The text of a fetched HTML page, PDF or plain-text file. */ export declare function pageText(page: FetchedPage): Promise; export type WebSourceArgs = { url: string; section?: number; }; export type LoadedWebSource = { url: URL; page: FetchedPage; content: WebPage & { pdf: boolean; }; snapshots: Snapshots; snapshotError: unknown; fromArchive: boolean; }; /** * Fetch a public page with its Wayback snapshots. When the live page fails * (but not at a bot check), read the latest archived copy instead. Returns an * error message instead of throwing. */ export declare function loadWebSource(ctx: PaperContext, rawUrl: string, log: ServiceLog, lookup?: Lookup): Promise; export type WebSourceResult = { text: string; isError?: boolean; }; export declare function readWebSource(ctx: PaperContext, args: WebSourceArgs, log: ServiceLog, lookup?: Lookup): Promise; export {};