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

    Function stripPdfLink

    • Removes the first PDF-linking anchor from a block of HTML — the removal counterpart to findPdfHref. Meant to be used together: pull the document's URL out with findPdfHref, then strip the anchor that pointed to it out of the surrounding text with this, so a supplier's "Download SDS"-style link text doesn't linger as dead text once its URL has been captured elsewhere (e.g. a product's sdsUrl).

      Parameters

      • html: string

        Raw HTML that may contain a PDF-linking anchor

      Returns string

      The HTML with the first <a href="….pdf">…</a> removed, or the original value unchanged if none is found

      stripPdfLink('<p><a href="https://x.com/sds.pdf">DOWNLOAD SDS</a></p><p>Body.</p>')
      // "<p></p><p>Body.</p>"
      stripPdfLink("<p>No documents here</p>") // "<p>No documents here</p>"
      export function stripPdfLink(html: string): string {
      if (!html || typeof html !== 'string') return html;
      return html.replace(PDF_ANCHOR_REGEX, '');
      }