(text, optionsCopy)
| 112 | |
| 113 | |
| 114 | const renderMathInText = function renderMathInText(text, optionsCopy) { |
| 115 | const data = splitWithDelimiters(text, optionsCopy.delimiters); |
| 116 | const fragment = document.createDocumentFragment(); |
| 117 | |
| 118 | for (let i = 0; i < data.length; i++) { |
| 119 | if (data[i].type === "text") { |
| 120 | fragment.appendChild(document.createTextNode(data[i].data)); |
| 121 | } else { |
| 122 | const span = document.createElement("span"); |
| 123 | let math = data[i].data; // Override any display mode defined in the settings with that |
| 124 | // defined by the text itself |
| 125 | |
| 126 | optionsCopy.displayMode = data[i].display; |
| 127 | |
| 128 | try { |
| 129 | if (optionsCopy.preProcess) { |
| 130 | math = optionsCopy.preProcess(math); |
| 131 | } |
| 132 | |
| 133 | katex.render(math, span, optionsCopy); |
| 134 | } catch (e) { |
| 135 | if (!(e instanceof katex.ParseError)) { |
| 136 | throw e; |
| 137 | } |
| 138 | |
| 139 | optionsCopy.errorCallback("KaTeX auto-render: Failed to parse `" + data[i].data + "` with ", e); |
| 140 | fragment.appendChild(document.createTextNode(data[i].rawData)); |
| 141 | continue; |
| 142 | } |
| 143 | |
| 144 | fragment.appendChild(span); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return fragment; |
| 149 | }; |
| 150 | |
| 151 | const renderElem = function renderElem(elem, optionsCopy) { |
| 152 | for (let i = 0; i < elem.childNodes.length; i++) { |
no test coverage detected