Skip to content

XSweet math fix

Dan Visel requested to merge math-fixes-again into main

Another document with failing math: MathSample_1.docx

What's happening here is different from the malformed HTML we were getting before. This is coming in like this:

<h1>Equation 1:</h1>
<h3>
</h3><h3><math-display class="math-node">
    $$\left(1+x\right)^{n}=1+\frac{nx}{1!}+\frac{n\left(n\hbox{--}1\right)x^{2}}{2!}+\ldots $$
  </math-display></h3>
<h2>Equation 2:</h2>

where there's an empty <h3> before the math and another <h3> around it. It should look like this:

<h1>Equation 1:</h1>
<p><math-display class="math-node">
    $$\left(1+x\right)^{n}=1+\frac{nx}{1!}+\frac{n\left(n\hbox{--}1\right)x^{2}}{2!}+\ldots $$
  </math-display></p>
<h2>Equation 2:</h2>

which is what this additional regex does, fixing the problem with the document. The previous regex was this:

  const dupedH4s = /<h4>\s*<h4>([\s\S]*?)<\/h4>\s*<\/h4>/g

This one is like this:

  const dupedH3s = /<h3>\s*<\/h3>\s*<h3>([\s\S]*?)\s*<\/h3>/g

Something's going wrong on the XSweet side; it's happening with both H3 and H4 potentially in two different configurations. Maybe we should be checking for multiple header types in both configurations?

Merge request reports