* Parses a size specification, consisting of magnitude and unit.
(optional)
| 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 | */ |
no test coverage detected