Skip to main content
Converts HTML content from a Playwright Page or Locator to semantic markdown format.
export declare function extractMarkdown(input: {
  source: Page | Locator;
}): Promise<string>;

Examples

import { extractMarkdown } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://books.toscrape.com/");
  const headerLocator = page.locator("h1").first(); // First title on the page
  const markdown = await extractMarkdown({ source: headerLocator }); // Extract markdown from the first title
  console.log(markdown);
  return markdown;
}

Arguments

input
Object
required
The input object containing the source of the HTML content

Returns: Promise<string>

Promise that resolves to the markdown representation of the HTML content