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

    Function makeURLAbsolute

    • Makes URLs absolute for a specific HTML tag and attribute.

      Generic function that finds all instances of a given tag and converts a specific attribute from relative to absolute URLs.

      Parameters

      • tag: string

        The HTML tag name to target (e.g., 'img', 'a', 'link')

      • attr: string

        The attribute name to convert (e.g., 'src', 'href')

      • hostname: string

        The base hostname/URL for resolving relative paths

      • html: string

        The HTML content to process

      Returns string

      HTML with the specified URLs converted to absolute

      // Convert video sources
      makeURLAbsolute('video', 'src', 'https://example.com', html);

      // Convert stylesheet links
      makeURLAbsolute('link', 'href', 'https://example.com', html);