auto-render: do not touch text nodes w/o formulas (#2154)

This commit is contained in:
Aleksey Nagovitsyn
2019-11-18 09:18:02 +05:00
committed by ylemkimon
parent d1cee3cf3d
commit 1e3471b290

View File

@@ -19,6 +19,13 @@ const splitWithDelimiters = function(text, delimiters) {
*/
const renderMathInText = function(text, optionsCopy) {
const data = splitWithDelimiters(text, optionsCopy.delimiters);
if (data.length === 1 && data[0].type === 'text') {
// There is no formula in the text.
// Let's return null which means there is no need to replace
// the current text node with a new one.
return null;
}
const fragment = document.createDocumentFragment();
for (let i = 0; i < data.length; i++) {
@@ -60,8 +67,10 @@ const renderElem = function(elem, optionsCopy) {
if (childNode.nodeType === 3) {
// Text node
const frag = renderMathInText(childNode.textContent, optionsCopy);
i += frag.childNodes.length - 1;
elem.replaceChild(frag, childNode);
if (frag) {
i += frag.childNodes.length - 1;
elem.replaceChild(frag, childNode);
}
} else if (childNode.nodeType === 1) {
// Element node
const className = ' ' + childNode.className + ' ';