ChemPal Documentation - v1.6.0
    Preparing search index...

    Function findPdfHref

    • Finds the href of the first PDF-linking anchor in a block of HTML. Useful for pulling out linked documents such as Safety Data Sheets or spec sheets that suppliers attach as <a href="….pdf"> inside descriptions or info sections.

      Parameters

      • html: string

        Raw HTML that may contain an anchor linking to a PDF

      Returns undefined | string

      The PDF URL, or undefined if none is found

      findPdfHref('<a href="https://x.com/sds.pdf" target="_blank">Safety Data Sheet</a>')
      // "https://x.com/sds.pdf"
      findPdfHref("<p>No documents here</p>") // undefined
      export function findPdfHref(html: string): string | undefined {
      if (!html || typeof html !== 'string') return undefined;
      return html.match(PDF_HREF_REGEX)?.[1];
      }