import { parseHTML } from "linkedom";
import { htmlToMarkdown } from "../markdown.js";
const STRIP_SELECTORS = [
  "nav",
  "aside",
  ".sidebar",
  ".sidebar-container",
  '[class*="sidebar"]',
  '[id*="sidebar"]',
  "header",
  "footer",
  ".bc-head",
  ".metadata",
  ".breadcrumbs-container",
  ".toc",
  ".document-toc",
  "nav.toc"
];
const mdnExtractor = {
  name: "mdn",
  canHandle(url) {
    try {
      const hostname = new URL(url).hostname;
      return hostname === "developer.mozilla.org";
    } catch {
      return false;
    }
  },
  extract(html, _url) {
    if (!html) return null;
    const { document } = parseHTML(html);
    const article = document.querySelector("article.main-page-content") ?? document.querySelector("main#content article") ?? document.querySelector("main#content") ?? document.querySelector(".section-content") ?? document.querySelector('[role="main"] article') ?? document.querySelector("article");
    if (!article) return null;
    for (const selector of STRIP_SELECTORS) {
      for (const el of Array.from(article.querySelectorAll(selector))) {
        el.parentNode?.removeChild(el);
      }
    }
    const articleH1 = article.querySelector("h1")?.textContent?.trim();
    const mainH1 = document.querySelector("main h1")?.textContent?.trim();
    const ogTitleEl = document.querySelector('meta[property="og:title"]');
    const ogTitle = ogTitleEl?.getAttribute("content")?.trim();
    const docTitle = document.querySelector("title")?.textContent?.trim();
    const candidateRaw = articleH1 || mainH1 || ogTitle || docTitle || "";
    const title = candidateRaw.includes("|") ? candidateRaw.split("|")[0].trim() : candidateRaw;
    if (!title) return null;
    const markdown = htmlToMarkdown(article.innerHTML).trim();
    if (!markdown) return null;
    return {
      title,
      markdown,
      metadata: {},
      links: [],
      images: [],
      extractor: "site-specific"
    };
  }
};
export {
  mdnExtractor
};
//# sourceMappingURL=mdn.js.map