mdfetch API Documentation - v1.0.0
    Preparing search index...

    Function readURL

    • Reads a URL and converts it to readable HTML, plain text, and markdown.

      This is the main entry point for the mdfetch library. It orchestrates the complete pipeline:

      1. Fetches HTML from the URL
      2. Makes all image and link paths absolute
      3. Extracts readable content using Mozilla Readability
      4. Converts to markdown using Turndown with GitHub Flavored Markdown support

      Features:

      • Returns content in three formats: HTML, plain text, and markdown
      • Preserves all article metadata (title, author, published date, etc.)
      • Supports customizable timeout and retry behavior
      • Automatic URL resolution for embedded resources
      • GFM support: tables, code blocks, strikethrough, task lists

      Parameters

      • url: string

        The URL of the web page to read and convert

      • Optionaloptions: ReaderOptions

        Optional configuration for fetching and processing

        Options for reading and converting web pages. Extends FetchOptions to inherit timeout, retries, and retryDelay.

        • Optionaltimeout?: number

          Request timeout in milliseconds (default: 30000)

        • Optionalretries?: number

          Number of retry attempts on failure (default: 3)

        • OptionalretryDelay?: number

          Delay between retries in milliseconds (default: 1000)

      Returns Promise<ConversionResult>

      Promise resolving to ConversionResult with content in all three formats

      When fetching fails, content cannot be extracted, or conversion encounters an error

      // Basic usage
      const result = await readURL('https://example.com/article');
      console.log(result.markdown); // Markdown version
      console.log(result.plainText); // Plain text version
      console.log(result.readableHTML); // Clean HTML version

      // With custom options
      const result = await readURL('https://example.com/article', {
      timeout: 60000,
      retries: 5
      });

      // Access metadata
      console.log(result.title); // Article title
      console.log(result.byline); // Author
      console.log(result.publishedTime);// Publication date