All files / utils containsParagraphTag.ts

85.71% Statements 6/7
83.33% Branches 5/6
100% Functions 1/1
83.33% Lines 5/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18          37x 37x   33x 33x 33x              
/**
 * Checks whether the given HTML string contains a paragraph (<p>) element
 */
 
export function containsParagraphTag(html: string | null | undefined): boolean {
  const input = (html ?? "").toString().trim();
  if (input === "") return false;
 
  Eif (typeof DOMParser !== "undefined") {
    const doc = new DOMParser().parseFromString(input, "text/html");
    return doc.body.querySelector("p") !== null;
  }
 
  return /<p\b[^>]*>/i.test(input);
}
 
export default containsParagraphTag;