| 1 | const KATEX_EQUATION_PARENT_SELECTOR = '.mtable > [class*=col-align]' |
| 2 | const KATEX_EQUATION_ROW_SELECTOR = ':scope > .vlist-t > .vlist-r > .vlist > span > .mord' |
| 3 | |
| 4 | export function collectKatexEquationLines(el: Element): Element[][] { |
| 5 | const equationParents = Array.from(el.querySelectorAll(KATEX_EQUATION_PARENT_SELECTOR)) |
| 6 | .filter(parent => !parent.parentElement?.closest(KATEX_EQUATION_PARENT_SELECTOR)) |
| 7 | |
| 8 | const lines: Element[][] = [] |
| 9 | for (const equationRowParent of equationParents) { |
| 10 | const equationRows = Array.from(equationRowParent.querySelectorAll(KATEX_EQUATION_ROW_SELECTOR)) |
| 11 | equationRows.forEach((equationRow, idx) => { |
| 12 | if (!equationRow) |
| 13 | return |
| 14 | if (Array.isArray(lines[idx])) |
| 15 | lines[idx].push(equationRow) |
| 16 | else |
| 17 | lines[idx] = [equationRow] |
| 18 | }) |
| 19 | } |
| 20 | |
| 21 | return lines |
| 22 | } |
| 23 |