Comparing version 0.11.0 to 0.11.1
# Changelog | ||
All notable changes to this project will be documented in this file. This CHANGELOG roughly follows the guidelines from [www.keepachangelog.com](https://keepachangelog.com/en/1.0.0/). | ||
## [v0.11.1] | ||
### Changed | ||
- [Security] Bump mixin-deep from 1.3.1 to 1.3.2 (#2090) | ||
- [Security] Bump eslint-utils from 1.3.1 to 1.4.2 (#2089) | ||
### Fixed | ||
- Fix parse timing by separating consume() into fetch() and consume() (#2054) | ||
- Use current font for accents (#2066) | ||
- Fix \gray's macro definition (#2075) | ||
## [v0.11.0] | ||
@@ -5,0 +15,0 @@ ### Added |
@@ -24,4 +24,4 @@ # Copy-tex extension | ||
```html | ||
<link href="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/copy-tex.css" rel="stylesheet" type="text/css"> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/copy-tex.min.js" integrity="sha384-XhWAe6BtVcvEdS3FFKT7Mcft4HJjPqMQvi5V4YhzH9Qxw497jC13TupOEvjoIPy7" crossorigin="anonymous"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/copy-tex.css" rel="stylesheet" type="text/css"> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/copy-tex.min.js" integrity="sha384-XhWAe6BtVcvEdS3FFKT7Mcft4HJjPqMQvi5V4YhzH9Qxw497jC13TupOEvjoIPy7" crossorigin="anonymous"></script> | ||
``` | ||
@@ -42,3 +42,3 @@ | ||
```html | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/copy-tex.mjs" integrity="sha384-kS7UtO844uqLwxPmaRwzg1nGbKiHsIteWh+DP2cvT2FtigL0v6w1yPXYKEDzct0C" crossorigin="anonymous"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/copy-tex.mjs" integrity="sha384-kS7UtO844uqLwxPmaRwzg1nGbKiHsIteWh+DP2cvT2FtigL0v6w1yPXYKEDzct0C" crossorigin="anonymous"></script> | ||
```` --> | ||
@@ -45,0 +45,0 @@ |
@@ -15,3 +15,3 @@ # `math/tex` Custom Script Type Extension | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/mathtex-script-type.min.js" integrity="sha384-LJ2FmexL77rmGm6SIpxq7y+XA6bkLzGZEgCywzKOZG/ws4va9fUVu2neMjvc3zdv"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/mathtex-script-type.min.js" integrity="sha384-LJ2FmexL77rmGm6SIpxq7y+XA6bkLzGZEgCywzKOZG/ws4va9fUVu2neMjvc3zdv"></script> | ||
``` | ||
@@ -27,8 +27,8 @@ You can download the script and use it locally, or from a local KaTeX installation instead. | ||
<head> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.css" integrity="sha384-BdGj8xC2eZkQaxoQ8nSLefg4AV4/AwB3Fj+8SUSo7pnKP6Eoy18liIKTPn9oBYNG" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.js" integrity="sha384-JiKN5O8x9Hhs/UE5cT5AAJqieYlOZbGT3CHws/y97o3ty4R7/O5poG9F3JoiOYw1" crossorigin="anonymous"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script> | ||
</head> | ||
<body> | ||
<script type="math/tex">x+\sqrt{1-x^2}</script> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/mathtex-script-type.min.js" integrity="sha384-LJ2FmexL77rmGm6SIpxq7y+XA6bkLzGZEgCywzKOZG/ws4va9fUVu2neMjvc3zdv"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/mathtex-script-type.min.js" integrity="sha384-LJ2FmexL77rmGm6SIpxq7y+XA6bkLzGZEgCywzKOZG/ws4va9fUVu2neMjvc3zdv"></script> | ||
</body> | ||
@@ -41,3 +41,3 @@ </html> | ||
```html | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/mathtex-script-type.mjs" integrity="sha384-qc7HqE4GHbr2H9R+C8mTSdJmkkZ9E1bkIRyRrxMsoj3dcbGjILzoXJGcBGGns1bk" crossorigin="anonymous"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/mathtex-script-type.mjs" integrity="sha384-qc7HqE4GHbr2H9R+C8mTSdJmkkZ9E1bkIRyRrxMsoj3dcbGjILzoXJGcBGGns1bk" crossorigin="anonymous"></script> | ||
```` --> |
@@ -10,3 +10,3 @@ # mhchem extension | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/mhchem.min.js" integrity="sha384-oa0lfxCGjaU1LdYckhq8LZcP+JTf8cyJXe69O6VE6UrShzWveT6KiCElJrck/stm"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/mhchem.min.js" integrity="sha384-oa0lfxCGjaU1LdYckhq8LZcP+JTf8cyJXe69O6VE6UrShzWveT6KiCElJrck/stm"></script> | ||
``` | ||
@@ -13,0 +13,0 @@ |
@@ -8,3 +8,3 @@ # [<img src="https://katex.org/img/katex-logo-black.svg" width="130" alt="KaTeX">](https://katex.org/) | ||
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/katex/badge?style=rounded)](https://www.jsdelivr.com/package/npm/katex) | ||
![](https://img.badgesize.io/KaTeX/KaTeX/v0.11.0/dist/katex.min.js?compression=gzip) | ||
![](https://img.badgesize.io/KaTeX/KaTeX/v0.11.1/dist/katex.min.js?compression=gzip) | ||
@@ -33,9 +33,9 @@ KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web. | ||
<head> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.css" integrity="sha384-BdGj8xC2eZkQaxoQ8nSLefg4AV4/AwB3Fj+8SUSo7pnKP6Eoy18liIKTPn9oBYNG" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> | ||
<!-- The loading of KaTeX is deferred to speed up page rendering --> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.js" integrity="sha384-JiKN5O8x9Hhs/UE5cT5AAJqieYlOZbGT3CHws/y97o3ty4R7/O5poG9F3JoiOYw1" crossorigin="anonymous"></script> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script> | ||
<!-- To automatically render math in text elements, include the auto-render extension: --> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" | ||
onload="renderMathInElement(document.body);"></script> | ||
@@ -42,0 +42,0 @@ </head> |
{ | ||
"name": "katex", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "Fast math typesetting for the web.", | ||
@@ -5,0 +5,0 @@ "main": "dist/katex.js", |
@@ -8,3 +8,3 @@ # [<img src="https://katex.org/img/katex-logo-black.svg" width="130" alt="KaTeX">](https://katex.org/) | ||
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/katex/badge?style=rounded)](https://www.jsdelivr.com/package/npm/katex) | ||
![](https://img.badgesize.io/KaTeX/KaTeX/v0.11.0/dist/katex.min.js?compression=gzip) | ||
![](https://img.badgesize.io/KaTeX/KaTeX/v0.11.1/dist/katex.min.js?compression=gzip) | ||
@@ -33,9 +33,9 @@ KaTeX is a fast, easy-to-use JavaScript library for TeX math rendering on the web. | ||
<head> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.css" integrity="sha384-BdGj8xC2eZkQaxoQ8nSLefg4AV4/AwB3Fj+8SUSo7pnKP6Eoy18liIKTPn9oBYNG" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> | ||
<!-- The loading of KaTeX is deferred to speed up page rendering --> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.js" integrity="sha384-JiKN5O8x9Hhs/UE5cT5AAJqieYlOZbGT3CHws/y97o3ty4R7/O5poG9F3JoiOYw1" crossorigin="anonymous"></script> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script> | ||
<!-- To automatically render math in text elements, include the auto-render extension: --> | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" | ||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" | ||
onload="renderMathInElement(document.body);"></script> | ||
@@ -42,0 +42,0 @@ </head> |
@@ -8,3 +8,3 @@ // @flow | ||
import type Options from "./Options"; | ||
import type {ArgType, BreakToken, Mode} from "./types"; | ||
import type {ArgType, BreakToken} from "./types"; | ||
import type {HtmlDomNode} from "./domTree"; | ||
@@ -89,10 +89,2 @@ import type {Token} from "./Token"; | ||
infix?: boolean, | ||
// Switch to the specified mode while consuming the command token. | ||
// This is useful for commands that switch between math and text mode, | ||
// for making sure that a switch happens early enough. Note that the | ||
// mode is switched immediately back to its original value after consuming | ||
// the command token, so that the argument parsing and/or function handler | ||
// can easily access the old mode while doing their own mode switching. | ||
consumeMode?: ?Mode, | ||
}; | ||
@@ -143,3 +135,2 @@ | ||
infix: boolean, | ||
consumeMode: ?Mode, | ||
@@ -203,3 +194,2 @@ // FLOW TYPE NOTES: Doing either one of the following two | ||
infix: !!props.infix, | ||
consumeMode: props.consumeMode, | ||
handler: handler, | ||
@@ -206,0 +196,0 @@ }; |
@@ -37,3 +37,3 @@ // @flow | ||
parser.consumeSpaces(); | ||
let nxt = parser.nextToken.text; | ||
let nxt = parser.fetch().text; | ||
while (nxt === "\\hline" || nxt === "\\hdashline") { | ||
@@ -43,3 +43,3 @@ parser.consume(); | ||
parser.consumeSpaces(); | ||
nxt = parser.nextToken.text; | ||
nxt = parser.fetch().text; | ||
} | ||
@@ -115,3 +115,3 @@ return hlineInfo; | ||
row.push(cell); | ||
const next = parser.nextToken.text; | ||
const next = parser.fetch().text; | ||
if (next === "&") { | ||
@@ -118,0 +118,0 @@ parser.consume(); |
@@ -97,4 +97,5 @@ // @flow | ||
} else { | ||
accent = buildCommon.makeSymbol( | ||
group.label, "Main-Regular", group.mode, options); | ||
accent = buildCommon.makeOrd({mode: group.mode, text: group.label}, | ||
options, "textord"); | ||
accent = assertSymbolDomNode(accent); | ||
// Remove the italic correction of the accent, because it only serves to | ||
@@ -101,0 +102,0 @@ // shift the accent over to a place we don't want. |
@@ -13,3 +13,2 @@ // @flow | ||
allowedInMath: false, | ||
consumeMode: "math", | ||
}, | ||
@@ -21,7 +20,4 @@ handler({funcName, parser}, args) { | ||
const body = parser.parseExpression(false, close); | ||
// We can't expand the next symbol after the closing $ until after | ||
// switching modes back. So don't consume within expect. | ||
parser.expect(close, false); | ||
parser.expect(close); | ||
parser.switchMode(outerMode); | ||
parser.consume(); | ||
return { | ||
@@ -28,0 +24,0 @@ type: "styling", |
@@ -53,3 +53,2 @@ // @flow | ||
allowedInText: true, | ||
consumeMode: "text", | ||
}, | ||
@@ -56,0 +55,0 @@ handler({parser, funcName}, args) { |
@@ -955,3 +955,3 @@ // @flow | ||
defineMacro("\\green", "\\textcolor{##28ae7b}{#1}"); | ||
defineMacro("\\gray", "\\textcolor{gray}{##1}"); | ||
defineMacro("\\gray", "\\textcolor{gray}{#1}"); | ||
defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}"); | ||
@@ -958,0 +958,0 @@ defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}"); |
@@ -58,3 +58,3 @@ // @flow | ||
leftrightDepth: number; | ||
nextToken: Token; | ||
nextToken: ?Token; | ||
@@ -78,6 +78,5 @@ constructor(input: string, settings: Settings) { | ||
expect(text: string, consume?: boolean = true) { | ||
if (this.nextToken.text !== text) { | ||
if (this.fetch().text !== text) { | ||
throw new ParseError( | ||
"Expected '" + text + "', got '" + this.nextToken.text + "'", | ||
this.nextToken | ||
`Expected '${text}', got '${this.fetch().text}'`, this.fetch() | ||
); | ||
@@ -91,10 +90,21 @@ } | ||
/** | ||
* Considers the current look ahead token as consumed, | ||
* and fetches the one after that as the new look ahead. | ||
* Discards the current lookahead token, considering it consumed. | ||
*/ | ||
consume() { | ||
this.nextToken = this.gullet.expandNextToken(); | ||
this.nextToken = null; | ||
} | ||
/** | ||
* Return the current lookahead token, or if there isn't one (at the | ||
* beginning, or if the previous lookahead token was consume()d), | ||
* fetch the next token as the new lookahead token and return it. | ||
*/ | ||
fetch(): Token { | ||
if (this.nextToken == null) { | ||
this.nextToken = this.gullet.expandNextToken(); | ||
} | ||
return this.nextToken; | ||
} | ||
/** | ||
* Switches between "text" and "math" modes. | ||
@@ -123,7 +133,6 @@ */ | ||
// Try to parse the input | ||
this.consume(); | ||
const parse = this.parseExpression(false); | ||
// If we succeeded, make sure there's an EOF at the end | ||
this.expect("EOF", false); | ||
this.expect("EOF"); | ||
@@ -166,3 +175,3 @@ // End the group namespace for the expression | ||
} | ||
const lex = this.nextToken; | ||
const lex = this.fetch(); | ||
if (Parser.endOfExpression.indexOf(lex.text) !== -1) { | ||
@@ -254,7 +263,8 @@ break; | ||
): AnyParseNode { | ||
const symbolToken = this.nextToken; | ||
const symbolToken = this.fetch(); | ||
const symbol = symbolToken.text; | ||
this.consume(); | ||
this.consumeSpaces(); // ignore spaces before sup/subscript argument | ||
const group = this.parseGroup(name, false, Parser.SUPSUB_GREEDINESS); | ||
const group = this.parseGroup(name, false, Parser.SUPSUB_GREEDINESS, | ||
undefined, undefined, true); | ||
// ignore spaces before sup/subscript argument | ||
@@ -320,3 +330,3 @@ if (!group) { | ||
// Lex the first token | ||
const lex = this.nextToken; | ||
const lex = this.fetch(); | ||
@@ -365,3 +375,3 @@ if (lex.text === "\\limits" || lex.text === "\\nolimits") { | ||
// Keep lexing tokens until we get something that's not a prime | ||
while (this.nextToken.text === "'") { | ||
while (this.fetch().text === "'") { | ||
// For each one, add another prime to the list | ||
@@ -373,3 +383,3 @@ primes.push(prime); | ||
// superscript in with the primes. | ||
if (this.nextToken.text === "^") { | ||
if (this.fetch().text === "^") { | ||
primes.push(this.handleSupSubscript("superscript")); | ||
@@ -410,3 +420,3 @@ } | ||
): ?AnyParseNode { | ||
const token = this.nextToken; | ||
const token = this.fetch(); | ||
const func = token.text; | ||
@@ -417,2 +427,4 @@ const funcData = functions[func]; | ||
} | ||
this.consume(); // consume command token | ||
if (greediness != null && funcData.greediness <= greediness) { | ||
@@ -430,18 +442,2 @@ throw new ParseError( | ||
// hyperref package sets the catcode of % as an active character | ||
if (funcData.argTypes && funcData.argTypes[0] === "url") { | ||
this.gullet.lexer.setCatcode("%", 13); | ||
} | ||
// Consume the command token after possibly switching to the | ||
// mode specified by the function (for instant mode switching), | ||
// and then immediately switch back. | ||
if (funcData.consumeMode) { | ||
const oldMode = this.mode; | ||
this.switchMode(funcData.consumeMode); | ||
this.consume(); | ||
this.switchMode(oldMode); | ||
} else { | ||
this.consume(); | ||
} | ||
const {args, optArgs} = this.parseArguments(func, funcData); | ||
@@ -501,17 +497,12 @@ return this.callFunction(func, args, optArgs, token, breakOnTokenText); | ||
// TeX doesn’t use single spaces as undelimited arguments." | ||
if (i > 0 && !isOptional) { | ||
this.consumeSpaces(); | ||
} | ||
const consumeSpaces = (i > 0 && !isOptional) || | ||
// Also consume leading spaces in math mode, as parseSymbol | ||
// won't know what to do with them. This can only happen with | ||
// macros, e.g. \frac\foo\foo where \foo expands to a space symbol. | ||
// In LaTeX, the \foo's get treated as (blank) arguments). | ||
// In LaTeX, the \foo's get treated as (blank) arguments. | ||
// In KaTeX, for now, both spaces will get consumed. | ||
// TODO(edemaine) | ||
if (i === 0 && !isOptional && this.mode === "math") { | ||
this.consumeSpaces(); | ||
} | ||
const nextToken = this.nextToken; | ||
const arg = this.parseGroupOfType("argument to '" + func + "'", | ||
argType, isOptional, baseGreediness); | ||
(i === 0 && !isOptional && this.mode === "math"); | ||
const arg = this.parseGroupOfType(`argument to '${func}'`, | ||
argType, isOptional, baseGreediness, consumeSpaces); | ||
if (!arg) { | ||
@@ -523,3 +514,3 @@ if (isOptional) { | ||
throw new ParseError( | ||
"Expected group after '" + func + "'", nextToken); | ||
`Expected group after '${func}'`, this.fetch()); | ||
} | ||
@@ -540,18 +531,26 @@ (isOptional ? optArgs : args).push(arg); | ||
greediness: ?number, | ||
consumeSpaces: boolean, | ||
): ?AnyParseNode { | ||
switch (type) { | ||
case "color": | ||
if (consumeSpaces) { | ||
this.consumeSpaces(); | ||
} | ||
return this.parseColorGroup(optional); | ||
case "size": | ||
if (consumeSpaces) { | ||
this.consumeSpaces(); | ||
} | ||
return this.parseSizeGroup(optional); | ||
case "url": | ||
return this.parseUrlGroup(optional); | ||
return this.parseUrlGroup(optional, consumeSpaces); | ||
case "math": | ||
case "text": | ||
return this.parseGroup(name, optional, greediness, undefined, type); | ||
return this.parseGroup( | ||
name, optional, greediness, undefined, type, consumeSpaces); | ||
case "hbox": { | ||
// hbox argument type wraps the argument in the equivalent of | ||
// \hbox, which is like \text but switching to \textstyle size. | ||
const group = this.parseGroup( | ||
name, optional, greediness, undefined, "text"); | ||
const group = this.parseGroup(name, optional, greediness, | ||
undefined, "text", consumeSpaces); | ||
if (!group) { | ||
@@ -569,3 +568,6 @@ return group; | ||
case "raw": { | ||
if (optional && this.nextToken.text === "{") { | ||
if (consumeSpaces) { | ||
this.consumeSpaces(); | ||
} | ||
if (optional && this.fetch().text === "{") { | ||
return null; | ||
@@ -581,3 +583,3 @@ } | ||
} else { | ||
throw new ParseError("Expected raw group", this.nextToken); | ||
throw new ParseError("Expected raw group", this.fetch()); | ||
} | ||
@@ -588,11 +590,15 @@ } | ||
case undefined: | ||
return this.parseGroup(name, optional, greediness); | ||
return this.parseGroup(name, optional, greediness, | ||
undefined, undefined, consumeSpaces); | ||
default: | ||
throw new ParseError( | ||
"Unknown group type as " + name, this.nextToken); | ||
"Unknown group type as " + name, this.fetch()); | ||
} | ||
} | ||
/** | ||
* Discard any space tokens, fetching the next non-space token. | ||
*/ | ||
consumeSpaces() { | ||
while (this.nextToken.text === " ") { | ||
while (this.fetch().text === " ") { | ||
this.consume(); | ||
@@ -613,12 +619,10 @@ } | ||
const groupEnd = optional ? "]" : "}"; | ||
const nextToken = this.nextToken; | ||
if (nextToken.text !== groupBegin) { | ||
const beginToken = this.fetch(); | ||
if (beginToken.text !== groupBegin) { | ||
if (optional) { | ||
return null; | ||
} else if (raw && nextToken.text !== "EOF" && | ||
/[^{}[\]]/.test(nextToken.text)) { | ||
// allow a single character in raw string group | ||
this.gullet.lexer.setCatcode("%", 14); // reset the catcode of % | ||
} else if (raw && beginToken.text !== "EOF" && | ||
/[^{}[\]]/.test(beginToken.text)) { | ||
this.consume(); | ||
return nextToken; | ||
return beginToken; | ||
} | ||
@@ -630,7 +634,9 @@ } | ||
let str = ""; | ||
const firstToken = this.nextToken; | ||
const firstToken = this.fetch(); | ||
let nested = 0; // allow nested braces in raw string group | ||
let lastToken = firstToken; | ||
while ((raw && nested > 0) || this.nextToken.text !== groupEnd) { | ||
switch (this.nextToken.text) { | ||
let nextToken; | ||
while ((nextToken = this.fetch()).text !== groupEnd || | ||
(raw && nested > 0)) { | ||
switch (nextToken.text) { | ||
case "EOF": | ||
@@ -647,9 +653,8 @@ throw new ParseError( | ||
} | ||
lastToken = this.nextToken; | ||
lastToken = nextToken; | ||
str += lastToken.text; | ||
this.consume(); | ||
} | ||
this.expect(groupEnd); | ||
this.mode = outerMode; | ||
this.gullet.lexer.setCatcode("%", 14); // reset the catcode of % | ||
this.expect(groupEnd); | ||
return firstToken.range(lastToken, str); | ||
@@ -669,8 +674,9 @@ } | ||
this.mode = "text"; | ||
const firstToken = this.nextToken; | ||
const firstToken = this.fetch(); | ||
let lastToken = firstToken; | ||
let str = ""; | ||
while (this.nextToken.text !== "EOF" && | ||
regex.test(str + this.nextToken.text)) { | ||
lastToken = this.nextToken; | ||
let nextToken; | ||
while ((nextToken = this.fetch()).text !== "EOF" && | ||
regex.test(str + nextToken.text)) { | ||
lastToken = nextToken; | ||
str += lastToken.text; | ||
@@ -720,3 +726,3 @@ this.consume(); | ||
let isBlank = false; | ||
if (!optional && this.nextToken.text !== "{") { | ||
if (!optional && this.fetch().text !== "{") { | ||
res = this.parseRegexGroup( | ||
@@ -757,6 +763,9 @@ /^[-+]? *(?:$|\d+|\d+\.\d*|\.\d*) *[a-z]{0,2} *$/, "size"); | ||
/** | ||
* Parses an URL, checking escaped letters and allowed protocols. | ||
* Parses an URL, checking escaped letters and allowed protocols, | ||
* and setting the catcode of % as an active character (as in \hyperref). | ||
*/ | ||
parseUrlGroup(optional: boolean): ?ParseNode<"url"> { | ||
parseUrlGroup(optional: boolean, consumeSpaces: boolean): ?ParseNode<"url"> { | ||
this.gullet.lexer.setCatcode("%", 13); // active character | ||
const res = this.parseStringGroup("url", optional, true); // get raw string | ||
this.gullet.lexer.setCatcode("%", 14); // comment character | ||
if (!res) { | ||
@@ -795,23 +804,31 @@ return null; | ||
mode?: Mode, | ||
consumeSpaces?: boolean, | ||
): ?AnyParseNode { | ||
// Switch to specified mode | ||
const outerMode = this.mode; | ||
const firstToken = this.nextToken; | ||
const text = firstToken.text; | ||
// Switch to specified mode | ||
if (mode) { | ||
this.switchMode(mode); | ||
} | ||
// Consume spaces if requested, crucially *after* we switch modes, | ||
// so that the next non-space token is parsed in the correct mode. | ||
if (consumeSpaces) { | ||
this.consumeSpaces(); | ||
} | ||
// Get first token | ||
const firstToken = this.fetch(); | ||
const text = firstToken.text; | ||
let groupEnd; | ||
let result; | ||
// Try to parse an open brace or \begingroup | ||
if (optional ? text === "[" : text === "{" || text === "\\begingroup") { | ||
groupEnd = Parser.endOfGroup[text]; | ||
this.consume(); | ||
const groupEnd = Parser.endOfGroup[text]; | ||
// Start a new group namespace | ||
this.gullet.beginGroup(); | ||
// If we get a brace, parse an expression | ||
this.consume(); | ||
const expression = this.parseExpression(false, groupEnd); | ||
const lastToken = this.nextToken; | ||
// End group namespace before consuming symbol after close brace | ||
const lastToken = this.fetch(); | ||
// Check that we got a matching closing brace | ||
this.expect(groupEnd); | ||
// End group namespace | ||
this.gullet.endGroup(); | ||
@@ -852,6 +869,2 @@ result = { | ||
} | ||
// Make sure we got a close brace | ||
if (groupEnd) { | ||
this.expect(groupEnd); | ||
} | ||
return result; | ||
@@ -907,6 +920,6 @@ } | ||
* Parse a single symbol out of the string. Here, we handle single character | ||
* symbols and special functions like verbatim | ||
* symbols and special functions like \verb. | ||
*/ | ||
parseSymbol(): ?AnyParseNode { | ||
const nucleus = this.nextToken; | ||
const nucleus = this.fetch(); | ||
let text = nucleus.text; | ||
@@ -913,0 +926,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57597
3942210