| 2 | |
| 3 | /* eslint no-constant-condition:0 */ |
| 4 | const findEndOfMath = function findEndOfMath(delimiter, text, startIndex) { |
| 5 | // Adapted from |
| 6 | // https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx |
| 7 | let index = startIndex; |
| 8 | let braceLevel = 0; |
| 9 | const delimLength = delimiter.length; |
| 10 | |
| 11 | while (index < text.length) { |
| 12 | const character = text[index]; |
| 13 | |
| 14 | if (braceLevel <= 0 && text.slice(index, index + delimLength) === delimiter) { |
| 15 | return index; |
| 16 | } else if (character === "\\") { |
| 17 | index++; |
| 18 | } else if (character === "{") { |
| 19 | braceLevel++; |
| 20 | } else if (character === "}") { |
| 21 | braceLevel--; |
| 22 | } |
| 23 | |
| 24 | index++; |
| 25 | } |
| 26 | |
| 27 | return -1; |
| 28 | }; |
| 29 | |
| 30 | const splitAtDelimiters = function splitAtDelimiters(startData, leftDelim, rightDelim, display) { |
| 31 | const finalData = []; |