@@ -40,52 +40,26 @@ MathJax = {
4040 .catch((err) => console.log('Typeset failed: ' + err.message));
4141 return MathJax.startup.promise;
4242 };
43-
44- const typesetCellObserver = new MutationObserver((mutationList, observer) => {
45- const els = mutationList.map((list) => list.target);
46- const typesetEls = [];
47- for (const el of els) {
48- const childMathEls = el.querySelectorAll('.quarto-inline-math, .quarto-display-math');
49- if (childMathEls && childMathEls.length > 0) {
50- typesetEls.push(...childMathEls);
51- }
52- }
53- typesetMath(typesetEls);
54- });
5543
5644 const containerObserver = new MutationObserver((mutationList, observer) => {
57- const nodes = [];
45+ const markdownNodes = [];
5846 mutationList.forEach((record) => {
5947 for (const node of record.addedNodes) {
60- nodes.push(node);
48+ if(node.querySelectorAll){
49+ markdownNodes.push(...node.querySelectorAll('.quarto-inline-math, .quarto-display-math'));
50+ }
6151 }
6252 });
63-
64- const markdownNodes = nodes.filter((node) => {
65- return node.classList.contains("jp-MarkdownCell");
66- }).forEach((node) => {
67- typesetCellObserver.observe(node, { childList: true, subtree: true });
68- });
69-
53+ typesetMath(markdownNodes);
7054 });
7155
72- const cellEl = document.querySelector('.jp-Cell');
73- if (cellEl !== null) {
74- const cellParentEl = cellEl.parentElement;
75- containerObserver.observe(cellParentEl, { childList: true });
76- } else {
77- const nbContainer = document.querySelector('.jp-Notebook');
78- if (nbContainer !== null) {
79- containerObserver.observe(nbContainer, { childList: true, subtree: true });
80- }
56+ const nbContainer = document.querySelector('.jp-Notebook');
57+ if (nbContainer !== null) {
58+ containerObserver.observe(nbContainer, { childList: true, subtree: true });
8159 }
8260
8361 const mathEls = document.body.querySelectorAll('.quarto-inline-math, .quarto-display-math');
84- return typesetMath([...mathEls]).then(() => {
85- for (const mathEl of mathEls) {
86- typesetCellObserver.observe(mathEl.parentElement, { childList: true, subtree: true });
87- }
88- });
62+ return typesetMath([...mathEls]);
8963 });
9064 },
9165 }
0 commit comments