\toggle causes the entire <body> to be removed from DOM when clicked if converted using `MathJax.tex2chtml`
Created by: lishid
Issue Summary
\toggle
causes the entire <body> to be removed from DOM when clicked if converted using MathJax.tex2chtml
(using the method from the example https://github.com/mathjax/MathJax-demos-web/blob/master/input-tex2chtml.html.md)
This does not seem to happen if the tex is parsed from DOM text.
Steps to Reproduce:
Fiddle link: https://jsfiddle.net/wq8gvca3/
Source:
<html>
<head>
<script type="text/javascript" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js"></script>
</head>
<body>
This text is part of the body. It will disappear once the toggle is clicked on.
<p id="container"></p>
This text is after the container.
<script>
document.getElementById('container')
.appendChild(MathJax.tex2chtml('\\toggle{math1}{math2}\\endtoggle'));
MathJax.startup.document.clear();
MathJax.startup.document.updateDocument();
</script>
</body>
</html>
Clicking on the toggle renders the entire document blank, and shows the following in the console.
Uncaught TypeError: Cannot read property 'parentNode' of null
at c.parent (tex-chtml-full.js:1)
at c.insert (tex-chtml-full.js:1)
at e.l.updateDocument (tex-chtml-full.js:1)
at Object.renderMath (tex-chtml-full.js:1)
at v.renderMath (tex-chtml-full.js:1)
at e.n.rerender (tex-chtml-full.js:1)
at HTMLElement.<anonymous> (tex-chtml-full.js:1)
Preliminary debugging suggests the removal came from: https://github.com/mathjax/MathJax-src/blob/1d5ce9837c82f1d12efec8da829c2138bd640c08/ts/handlers/html/HTMLMathItem.ts#L87
Seems like the start node was set to the
element rather than the element that's actual rendered.Technical details:
- MathJax Version: 3.0.5 (tex-chtml-full)
- Client OS: Windows 10 1909
- Browser: Chrome 83.0.4103.116