JSFiddle - React, Tailwind, and code Playground

JavaScript

function processHtml(inputHtml) {
  // Создаешь временный DOM для парсинга HTML
  
  const parser = new DOMParser();
  const doc = parser.parseFromString(inputHtml, 'text/html');

  // Обрабатываешь span внутри p
  doc.querySelectorAll('p span[style]').forEach((span) => {
    const style = span.getAttribute('style');
    const fontSizeMatch = style.match(/font-size:\s*([\d.]+)pt/);
    const fontWeightMatch = style.match(/font-weight:\s*(\d+)/);
  // дописать остальные регулярки (font-style и т.д.)

    let newElement;

    if (fontSizeMatch) {
      const fontSize = parseFloat(fontSizeMatch[1]);
      
      if (fontSize >= 18) {
        newElement = document.createElement('h2');
      } else if (fontSize >= 16) {
        newElement = document.createElement('h3');
      }
    }

    if (!newElement && fontWeightMatch) {
      const fontWeight = parseInt(fontWeightMatch[1], 10);
   
      if (fontWeight >= 700) {
        newElement = document.createElement('strong');
      }
    }

    // Если замена нашлась, то создаешь новый элемент
    if (newElement) {
      newElement.textContent = span.textContent;
      span.replaceWith(newElement);
    }
  });

  // Удаляешь лишние стили из p

  doc.querySelectorAll('p').forEach((p) => {
    p.removeAttribute('style');
  });

   return doc.body.innerHTML; // возвращаешь обработанный html
}



const inputHtml = `
<p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;">
<span style="font-size:18pt;font-family:Calibri,sans-serif;color:#000000;background-color:#ffffff;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">
   Тут текст
</span>
</p>`;

const resultHtml = processHtml(inputHtml);
console.log(resultHtml);