katex 0.16.20 → 0.16.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/katex.mjs CHANGED
@@ -3942,10 +3942,20 @@ var toNode = function toNode(tagName) {
3942
3942
  return node;
3943
3943
  };
3944
3944
  /**
3945
- * Convert into an HTML markup string
3945
+ * https://w3c.github.io/html-reference/syntax.html#syntax-attributes
3946
+ *
3947
+ * > Attribute Names must consist of one or more characters
3948
+ * other than the space characters, U+0000 NULL,
3949
+ * '"', "'", ">", "/", "=", the control characters,
3950
+ * and any characters that are not defined by Unicode.
3946
3951
  */
3947
3952
 
3948
3953
 
3954
+ var invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
3955
+ /**
3956
+ * Convert into an HTML markup string
3957
+ */
3958
+
3949
3959
  var toMarkup = function toMarkup(tagName) {
3950
3960
  var markup = "<" + tagName; // Add the class
3951
3961
 
@@ -3968,6 +3978,10 @@ var toMarkup = function toMarkup(tagName) {
3968
3978
 
3969
3979
  for (var attr in this.attributes) {
3970
3980
  if (this.attributes.hasOwnProperty(attr)) {
3981
+ if (invalidAttributeNameRegex.test(attr)) {
3982
+ throw new ParseError("Invalid attribute name '" + attr + "'");
3983
+ }
3984
+
3971
3985
  markup += " " + attr + "=\"" + utils.escape(this.attributes[attr]) + "\"";
3972
3986
  }
3973
3987
  }
@@ -5087,7 +5101,7 @@ defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
5087
5101
 
5088
5102
  defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
5089
5103
 
5090
- defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
5104
+ defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaeresis
5091
5105
 
5092
5106
  defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
5093
5107
 
@@ -13838,7 +13852,8 @@ defineFunction({
13838
13852
  names: ["\\relax"],
13839
13853
  props: {
13840
13854
  numArgs: 0,
13841
- allowedInText: true
13855
+ allowedInText: true,
13856
+ allowedInArgument: true
13842
13857
  },
13843
13858
 
13844
13859
  handler(_ref) {
@@ -14464,7 +14479,7 @@ defineFunctionBuilders({
14464
14479
  },
14465
14480
 
14466
14481
  mathmlBuilder(group, options) {
14467
- // Is the inner group a relevant horizonal brace?
14482
+ // Is the inner group a relevant horizontal brace?
14468
14483
  var isBrace = false;
14469
14484
  var isOver;
14470
14485
  var isSup;
@@ -17373,6 +17388,7 @@ class Parser {
17373
17388
  if (!atom) {
17374
17389
  break;
17375
17390
  } else if (atom.type === "internal") {
17391
+ // Internal nodes do not appear in parse tree
17376
17392
  continue;
17377
17393
  }
17378
17394
 
@@ -17459,8 +17475,15 @@ class Parser {
17459
17475
  var symbol = symbolToken.text;
17460
17476
  this.consume();
17461
17477
  this.consumeSpaces(); // ignore spaces before sup/subscript argument
17478
+ // Skip over allowed internal nodes such as \relax
17479
+
17480
+ var group;
17481
+
17482
+ do {
17483
+ var _group;
17462
17484
 
17463
- var group = this.parseGroup(name);
17485
+ group = this.parseGroup(name);
17486
+ } while (((_group = group) == null ? void 0 : _group.type) === "internal");
17464
17487
 
17465
17488
  if (!group) {
17466
17489
  throw new ParseError("Expected group after '" + symbol + "'", symbolToken);
@@ -17506,7 +17529,13 @@ class Parser {
17506
17529
  parseAtom(breakOnTokenText) {
17507
17530
  // The body of an atom is an implicit group, so that things like
17508
17531
  // \left(x\right)^2 work correctly.
17509
- var base = this.parseGroup("atom", breakOnTokenText); // In text mode, we don't have superscripts or subscripts
17532
+ var base = this.parseGroup("atom", breakOnTokenText); // Internal nodes (e.g. \relax) cannot support super/subscripts.
17533
+ // Instead we will pick up super/subscripts with blank base next round.
17534
+
17535
+ if ((base == null ? void 0 : base.type) === "internal") {
17536
+ return base;
17537
+ } // In text mode, we don't have superscripts or subscripts
17538
+
17510
17539
 
17511
17540
  if (this.mode === "text") {
17512
17541
  return base;
@@ -17793,13 +17822,13 @@ class Parser {
17793
17822
  throw new ParseError("A primitive argument cannot be optional");
17794
17823
  }
17795
17824
 
17796
- var _group = this.parseGroup(name);
17825
+ var _group2 = this.parseGroup(name);
17797
17826
 
17798
- if (_group == null) {
17827
+ if (_group2 == null) {
17799
17828
  throw new ParseError("Expected group as " + name, this.fetch());
17800
17829
  }
17801
17830
 
17802
- return _group;
17831
+ return _group2;
17803
17832
  }
17804
17833
 
17805
17834
  case "original":
@@ -18416,7 +18445,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
18416
18445
  }
18417
18446
  };
18418
18447
 
18419
- var version = "0.16.20";
18448
+ var version = "0.16.22";
18420
18449
  var __domTree = {
18421
18450
  Span,
18422
18451
  Anchor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.20",
3
+ "version": "0.16.22",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
package/src/Parser.js CHANGED
@@ -211,6 +211,7 @@ export default class Parser {
211
211
  if (!atom) {
212
212
  break;
213
213
  } else if (atom.type === "internal") {
214
+ // Internal nodes do not appear in parse tree
214
215
  continue;
215
216
  }
216
217
  body.push(atom);
@@ -286,7 +287,12 @@ export default class Parser {
286
287
  const symbol = symbolToken.text;
287
288
  this.consume();
288
289
  this.consumeSpaces(); // ignore spaces before sup/subscript argument
289
- const group = this.parseGroup(name);
290
+
291
+ // Skip over allowed internal nodes such as \relax
292
+ let group: ?AnyParseNode;
293
+ do {
294
+ group = this.parseGroup(name);
295
+ } while (group?.type === "internal");
290
296
 
291
297
  if (!group) {
292
298
  throw new ParseError(
@@ -333,6 +339,12 @@ export default class Parser {
333
339
  // \left(x\right)^2 work correctly.
334
340
  const base = this.parseGroup("atom", breakOnTokenText);
335
341
 
342
+ // Internal nodes (e.g. \relax) cannot support super/subscripts.
343
+ // Instead we will pick up super/subscripts with blank base next round.
344
+ if (base?.type === "internal") {
345
+ return base;
346
+ }
347
+
336
348
  // In text mode, we don't have superscripts or subscripts
337
349
  if (this.mode === "text") {
338
350
  return base;
package/src/domTree.js CHANGED
@@ -17,6 +17,7 @@ import {path} from "./svgGeometry";
17
17
  import type Options from "./Options";
18
18
  import {DocumentFragment} from "./tree";
19
19
  import {makeEm} from "./units";
20
+ import ParseError from "./ParseError";
20
21
 
21
22
  import type {VirtualNode} from "./tree";
22
23
 
@@ -83,6 +84,16 @@ const toNode = function(tagName: string): HTMLElement {
83
84
  return node;
84
85
  };
85
86
 
87
+ /**
88
+ * https://w3c.github.io/html-reference/syntax.html#syntax-attributes
89
+ *
90
+ * > Attribute Names must consist of one or more characters
91
+ * other than the space characters, U+0000 NULL,
92
+ * '"', "'", ">", "/", "=", the control characters,
93
+ * and any characters that are not defined by Unicode.
94
+ */
95
+ const invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
96
+
86
97
  /**
87
98
  * Convert into an HTML markup string
88
99
  */
@@ -110,6 +121,9 @@ const toMarkup = function(tagName: string): string {
110
121
  // Add the attributes
111
122
  for (const attr in this.attributes) {
112
123
  if (this.attributes.hasOwnProperty(attr)) {
124
+ if (invalidAttributeNameRegex.test(attr)) {
125
+ throw new ParseError(`Invalid attribute name '${attr}'`);
126
+ }
113
127
  markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
114
128
  }
115
129
  }
@@ -7,6 +7,7 @@ defineFunction({
7
7
  props: {
8
8
  numArgs: 0,
9
9
  allowedInText: true,
10
+ allowedInArgument: true,
10
11
  },
11
12
  handler({parser}) {
12
13
  return {
@@ -192,7 +192,7 @@ defineFunctionBuilders({
192
192
  options);
193
193
  },
194
194
  mathmlBuilder(group, options) {
195
- // Is the inner group a relevant horizonal brace?
195
+ // Is the inner group a relevant horizontal brace?
196
196
  let isBrace = false;
197
197
  let isOver;
198
198
  let isSup;
package/src/symbols.js CHANGED
@@ -711,7 +711,7 @@ defineSymbol(text, main, accent, "\u02d9", "\\."); // dot above
711
711
  defineSymbol(text, main, accent, "\u00b8", "\\c"); // cedilla
712
712
  defineSymbol(text, main, accent, "\u02da", "\\r"); // ring above
713
713
  defineSymbol(text, main, accent, "\u02c7", "\\v"); // caron
714
- defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaresis
714
+ defineSymbol(text, main, accent, "\u00a8", '\\"'); // diaeresis
715
715
  defineSymbol(text, main, accent, "\u02dd", "\\H"); // double acute
716
716
  defineSymbol(text, main, accent, "\u25ef", "\\textcircled"); // \bigcirc glyph
717
717