Skip to content

Commit

Permalink
Improve merging of math lists (mathjax/MathJax#3301).
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Oct 24, 2024
1 parent 43bb7d9 commit d50a25e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ts/handlers/html/HTMLDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ export class HTMLDocument<N, T, D> extends AbstractMathDocument<N, T, D> {
nodes: HTMLNodeArray<N, T>
): Location<N, T> {
const adaptor = this.adaptor;
for (const list of nodes[N]) {
const [node, n] = list;
const inc = 1 / (nodes[N].length || 1);
let i = N;
for (const [node, n] of nodes[N]) {
if (index <= n && adaptor.kind(node) === '#text') {
return { node: node, n: Math.max(index, 0), delim: delim };
return { i, node, n: Math.max(index, 0), delim };
}
index -= n;
i += inc;
}
return { node: null, n: 0, delim: delim };
return { node: null, n: 0, delim };
}

/**
Expand Down Expand Up @@ -298,9 +300,9 @@ export class HTMLDocument<N, T, D> extends AbstractMathDocument<N, T, D> {
/**
* @param {N} head The document <head>
* @param {string} id The id of the stylesheet to find
* @param {N|null} The stylesheet with the given ID
* @returns {N|null} The stylesheet with the given ID
*/
protected findSheet(head: N, id: string) {
protected findSheet(head: N, id: string): N | null {
if (id) {
for (const sheet of this.adaptor.tags(head, 'style')) {
if (this.adaptor.getAttribute(sheet, 'id') === id) {
Expand Down

0 comments on commit d50a25e

Please sign in to comment.