/** * HTML -> clean markdown extraction, with lazy + graceful dependency loading. * * The heavy deps (@mozilla/readability, jsdom, turndown) are imported on first * use so the extension loads instantly and degrades to a clear "run npm * install" message when they're absent. */ // Types derived from the real modules (kept loose where the libs ship `any`). type ReadabilityCtor = (typeof import("@mozilla/readability"))["Readability"]; type JSDOMCtor = (typeof import("jsdom"))["JSDOM"]; // turndown's default export is the service class; the instance has .turndown(). interface TurndownService { turndown(html: string): string; remove(tags: string[]): void; } export interface Extractor { Readability: ReadabilityCtor; JSDOM: JSDOMCtor; turndown: TurndownService; } export const DEP_SPECS = ["@mozilla/readability", "jsdom", "turndown"] as const; // --------------------------------------------------------------------------- // JSDOM silent VirtualConsole (suppresses CSS-parse warnings etc.) // --------------------------------------------------------------------------- let _silentVc: import("jsdom").VirtualConsole | undefined; async function getSilentVirtualConsole(): Promise { if (!_silentVc) { const jsdom = await import("jsdom"); _silentVc = new jsdom.VirtualConsole(); // Swallow everything — we only care about actual errors, not noisy // warnings from malformed