MCPcopy Index your code
hub / github.com/TruthHun/BookStack / parseSizeGroup

Method parseSizeGroup

static/katex/katex.mjs:15541–15586  ·  view source on GitHub ↗

* Parses a size specification, consisting of magnitude and unit.

(optional)

Source from the content-addressed store, hash-verified

15539
15540
15541 parseSizeGroup(optional) {
15542 let res;
15543 let isBlank = false;
15544
15545 if (!optional && this.nextToken.text !== "{") {
15546 res = this.parseRegexGroup(/^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size");
15547 } else {
15548 res = this.parseStringGroup("size", optional);
15549 }
15550
15551 if (!res) {
15552 return null;
15553 }
15554
15555 if (!optional && res.text.length === 0) {
15556 // Because we've tested for what is !optional, this block won't
15557 // affect \kern, \hspace, etc. It will capture the mandatory arguments
15558 // to \genfrac and \above.
15559 res.text = "0pt"; // Enable \above{}
15560
15561 isBlank = true; // This is here specifically for \genfrac
15562 }
15563
15564 const match = /([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(res.text);
15565
15566 if (!match) {
15567 throw new ParseError("Invalid size: '" + res.text + "'", res);
15568 }
15569
15570 const data = {
15571 number: +(match[1] + match[2]),
15572 // sign + magnitude, cast to number
15573 unit: match[3]
15574 };
15575
15576 if (!validUnit(data)) {
15577 throw new ParseError("Invalid unit: '" + data.unit + "'", res);
15578 }
15579
15580 return {
15581 type: "size",
15582 mode: this.mode,
15583 value: data,
15584 isBlank
15585 };
15586 }
15587 /**
15588 * Parses an URL, checking escaped letters and allowed protocols.
15589 */

Callers 3

parseGroupOfTypeMethod · 0.95
katex.jsFile · 0.80
katex.min.jsFile · 0.80

Calls 3

parseRegexGroupMethod · 0.95
parseStringGroupMethod · 0.95
validUnitFunction · 0.70

Tested by

no test coverage detected