Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auto-render): concatenate content of successive text nodes #3422

Merged
merged 12 commits into from Aug 29, 2022
12 changes: 11 additions & 1 deletion contrib/auto-render/auto-render.js
Expand Up @@ -55,7 +55,17 @@ const renderElem = function(elem, optionsCopy) {
const childNode = elem.childNodes[i];
if (childNode.nodeType === 3) {
// Text node
const frag = renderMathInText(childNode.textContent, optionsCopy);
// Concatenate all sibling text nodes.
// Webkit browsers split very large text nodes into smaller ones,
// so the delimiters may be split across different nodes.
let textContentConcat = childNode.textContent;
let sibling = childNode.nextSibling;
while (sibling && (sibling.nodeType == 3)) {
textContentConcat += sibling.textContent;
sibling.remove();
ylemkimon marked this conversation as resolved.
Show resolved Hide resolved
sibling = childNode.nextSibling;
}
const frag = renderMathInText(textContentConcat, optionsCopy);
if (frag) {
i += frag.childNodes.length - 1;
elem.replaceChild(frag, childNode);
Expand Down