(startData, leftDelim, rightDelim, display)
| 140 | }; |
| 141 | |
| 142 | var splitAtDelimiters = function splitAtDelimiters(startData, leftDelim, rightDelim, display) { |
| 143 | var finalData = []; |
| 144 | |
| 145 | for (var i = 0; i < startData.length; i++) { |
| 146 | if (startData[i].type === "text") { |
| 147 | var text = startData[i].data; |
| 148 | var lookingForLeft = true; |
| 149 | var currIndex = 0; |
| 150 | var nextIndex = void 0; |
| 151 | nextIndex = text.indexOf(leftDelim); |
| 152 | |
| 153 | if (nextIndex !== -1) { |
| 154 | currIndex = nextIndex; |
| 155 | finalData.push({ |
| 156 | type: "text", |
| 157 | data: text.slice(0, currIndex) |
| 158 | }); |
| 159 | lookingForLeft = false; |
| 160 | } |
| 161 | |
| 162 | while (true) { |
| 163 | if (lookingForLeft) { |
| 164 | nextIndex = text.indexOf(leftDelim, currIndex); |
| 165 | |
| 166 | if (nextIndex === -1) { |
| 167 | break; |
| 168 | } |
| 169 | |
| 170 | finalData.push({ |
| 171 | type: "text", |
| 172 | data: text.slice(currIndex, nextIndex) |
| 173 | }); |
| 174 | currIndex = nextIndex; |
| 175 | } else { |
| 176 | nextIndex = findEndOfMath(rightDelim, text, currIndex + leftDelim.length); |
| 177 | |
| 178 | if (nextIndex === -1) { |
| 179 | break; |
| 180 | } |
| 181 | |
| 182 | finalData.push({ |
| 183 | type: "math", |
| 184 | data: text.slice(currIndex + leftDelim.length, nextIndex), |
| 185 | rawData: text.slice(currIndex, nextIndex + rightDelim.length), |
| 186 | display: display |
| 187 | }); |
| 188 | currIndex = nextIndex + rightDelim.length; |
| 189 | } |
| 190 | |
| 191 | lookingForLeft = !lookingForLeft; |
| 192 | } |
| 193 | |
| 194 | finalData.push({ |
| 195 | type: "text", |
| 196 | data: text.slice(currIndex) |
| 197 | }); |
| 198 | } else { |
| 199 | finalData.push(startData[i]); |
nothing calls this directly
no test coverage detected