MCPcopy Create free account
hub / github.com/TruthHun/BookStack / findEndOfMath

Function findEndOfMath

static/katex/contrib/auto-render.mjs:4–28  ·  view source on GitHub ↗
(delimiter, text, startIndex)

Source from the content-addressed store, hash-verified

2
3/* eslint no-constant-condition:0 */
4const 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
30const splitAtDelimiters = function splitAtDelimiters(startData, leftDelim, rightDelim, display) {
31 const finalData = [];

Callers 1

splitAtDelimitersFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected