katex 0.16.16 → 0.16.17

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
@@ -6677,7 +6677,19 @@ class MathNode {
6677
6677
  }
6678
6678
 
6679
6679
  for (var i = 0; i < this.children.length; i++) {
6680
- node.appendChild(this.children[i].toNode());
6680
+ // Combine multiple TextNodes into one TextNode, to prevent
6681
+ // screen readers from reading each as a separate word [#3995]
6682
+ if (this.children[i] instanceof TextNode && this.children[i + 1] instanceof TextNode) {
6683
+ var text = this.children[i].toText() + this.children[++i].toText();
6684
+
6685
+ while (this.children[i + 1] instanceof TextNode) {
6686
+ text += this.children[++i].toText();
6687
+ }
6688
+
6689
+ node.appendChild(new TextNode(text).toNode());
6690
+ } else {
6691
+ node.appendChild(this.children[i].toNode());
6692
+ }
6681
6693
  }
6682
6694
 
6683
6695
  return node;
@@ -6947,12 +6959,34 @@ var getVariant = function getVariant(group, options) {
6947
6959
 
6948
6960
  return null;
6949
6961
  };
6962
+ /**
6963
+ * Check for <mi>.</mi> which is how a dot renders in MathML,
6964
+ * or <mo separator="true" lspace="0em" rspace="0em">,</mo>
6965
+ * which is how a braced comma {,} renders in MathML
6966
+ */
6967
+
6968
+ function isNumberPunctuation(group) {
6969
+ if (!group) {
6970
+ return false;
6971
+ }
6972
+
6973
+ if (group.type === 'mi' && group.children.length === 1) {
6974
+ var child = group.children[0];
6975
+ return child instanceof TextNode && child.text === '.';
6976
+ } else if (group.type === 'mo' && group.children.length === 1 && group.getAttribute('separator') === 'true' && group.getAttribute('lspace') === '0em' && group.getAttribute('rspace') === '0em') {
6977
+ var _child = group.children[0];
6978
+ return _child instanceof TextNode && _child.text === ',';
6979
+ } else {
6980
+ return false;
6981
+ }
6982
+ }
6950
6983
  /**
6951
6984
  * Takes a list of nodes, builds them, and returns a list of the generated
6952
6985
  * MathML nodes. Also combine consecutive <mtext> outputs into a single
6953
6986
  * <mtext> tag.
6954
6987
  */
6955
6988
 
6989
+
6956
6990
  var buildExpression = function buildExpression(expression, options, isOrdgroup) {
6957
6991
  if (expression.length === 1) {
6958
6992
  var group = buildGroup(expression[0], options);
@@ -6981,22 +7015,30 @@ var buildExpression = function buildExpression(expression, options, isOrdgroup)
6981
7015
  } else if (_group.type === 'mn' && lastGroup.type === 'mn') {
6982
7016
  lastGroup.children.push(..._group.children);
6983
7017
  continue; // Concatenate <mn>...</mn> followed by <mi>.</mi>
6984
- } else if (_group.type === 'mi' && _group.children.length === 1 && lastGroup.type === 'mn') {
6985
- var child = _group.children[0];
7018
+ } else if (isNumberPunctuation(_group) && lastGroup.type === 'mn') {
7019
+ lastGroup.children.push(..._group.children);
7020
+ continue; // Concatenate <mi>.</mi> followed by <mn>...</mn>
7021
+ } else if (_group.type === 'mn' && isNumberPunctuation(lastGroup)) {
7022
+ _group.children = [...lastGroup.children, ..._group.children];
7023
+ groups.pop(); // Put preceding <mn>...</mn> or <mi>.</mi> inside base of
7024
+ // <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
7025
+ } else if ((_group.type === 'msup' || _group.type === 'msub') && _group.children.length >= 1 && (lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))) {
7026
+ var base = _group.children[0];
7027
+
7028
+ if (base instanceof MathNode && base.type === 'mn') {
7029
+ base.children = [...lastGroup.children, ...base.children];
7030
+ groups.pop();
7031
+ } // \not
6986
7032
 
6987
- if (child instanceof TextNode && child.text === '.') {
6988
- lastGroup.children.push(..._group.children);
6989
- continue;
6990
- }
6991
7033
  } else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
6992
7034
  var lastChild = lastGroup.children[0];
6993
7035
 
6994
7036
  if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (_group.type === 'mo' || _group.type === 'mi' || _group.type === 'mn')) {
6995
- var _child = _group.children[0];
7037
+ var child = _group.children[0];
6996
7038
 
6997
- if (_child instanceof TextNode && _child.text.length > 0) {
7039
+ if (child instanceof TextNode && child.text.length > 0) {
6998
7040
  // Overlay with combining character long solidus
6999
- _child.text = _child.text.slice(0, 1) + "\u0338" + _child.text.slice(1);
7041
+ child.text = child.text.slice(0, 1) + "\u0338" + child.text.slice(1);
7000
7042
  groups.pop();
7001
7043
  }
7002
7044
  }
@@ -18371,7 +18413,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
18371
18413
  }
18372
18414
  };
18373
18415
 
18374
- var version = "0.16.16";
18416
+ var version = "0.16.17";
18375
18417
  var __domTree = {
18376
18418
  Span,
18377
18419
  Anchor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.16",
3
+ "version": "0.16.17",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
@@ -128,6 +128,30 @@ export const getVariant = function(
128
128
  return null;
129
129
  };
130
130
 
131
+ /**
132
+ * Check for <mi>.</mi> which is how a dot renders in MathML,
133
+ * or <mo separator="true" lspace="0em" rspace="0em">,</mo>
134
+ * which is how a braced comma {,} renders in MathML
135
+ */
136
+ function isNumberPunctuation(group: ?MathNode): boolean {
137
+ if (!group) {
138
+ return false;
139
+ }
140
+ if (group.type === 'mi' && group.children.length === 1) {
141
+ const child = group.children[0];
142
+ return child instanceof TextNode && child.text === '.';
143
+ } else if (group.type === 'mo' && group.children.length === 1 &&
144
+ group.getAttribute('separator') === 'true' &&
145
+ group.getAttribute('lspace') === '0em' &&
146
+ group.getAttribute('rspace') === '0em'
147
+ ) {
148
+ const child = group.children[0];
149
+ return child instanceof TextNode && child.text === ',';
150
+ } else {
151
+ return false;
152
+ }
153
+ }
154
+
131
155
  /**
132
156
  * Takes a list of nodes, builds them, and returns a list of the generated
133
157
  * MathML nodes. Also combine consecutive <mtext> outputs into a single
@@ -165,13 +189,25 @@ export const buildExpression = function(
165
189
  lastGroup.children.push(...group.children);
166
190
  continue;
167
191
  // Concatenate <mn>...</mn> followed by <mi>.</mi>
168
- } else if (group.type === 'mi' && group.children.length === 1 &&
169
- lastGroup.type === 'mn') {
170
- const child = group.children[0];
171
- if (child instanceof TextNode && child.text === '.') {
172
- lastGroup.children.push(...group.children);
173
- continue;
192
+ } else if (isNumberPunctuation(group) && lastGroup.type === 'mn') {
193
+ lastGroup.children.push(...group.children);
194
+ continue;
195
+ // Concatenate <mi>.</mi> followed by <mn>...</mn>
196
+ } else if (group.type === 'mn' && isNumberPunctuation(lastGroup)) {
197
+ group.children = [...lastGroup.children, ...group.children];
198
+ groups.pop();
199
+ // Put preceding <mn>...</mn> or <mi>.</mi> inside base of
200
+ // <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
201
+ } else if ((group.type === 'msup' || group.type === 'msub') &&
202
+ group.children.length >= 1 &&
203
+ (lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))
204
+ ) {
205
+ const base = group.children[0];
206
+ if (base instanceof MathNode && base.type === 'mn') {
207
+ base.children = [...lastGroup.children, ...base.children];
208
+ groups.pop();
174
209
  }
210
+ // \not
175
211
  } else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
176
212
  const lastChild = lastGroup.children[0];
177
213
  if (lastChild instanceof TextNode && lastChild.text === '\u0338' &&
package/src/mathMLTree.js CHANGED
@@ -95,7 +95,18 @@ export class MathNode implements MathDomNode {
95
95
  }
96
96
 
97
97
  for (let i = 0; i < this.children.length; i++) {
98
- node.appendChild(this.children[i].toNode());
98
+ // Combine multiple TextNodes into one TextNode, to prevent
99
+ // screen readers from reading each as a separate word [#3995]
100
+ if (this.children[i] instanceof TextNode &&
101
+ this.children[i + 1] instanceof TextNode) {
102
+ let text = this.children[i].toText() + this.children[++i].toText();
103
+ while (this.children[i + 1] instanceof TextNode) {
104
+ text += this.children[++i].toText();
105
+ }
106
+ node.appendChild(new TextNode(text).toNode());
107
+ } else {
108
+ node.appendChild(this.children[i].toNode());
109
+ }
99
110
  }
100
111
 
101
112
  return node;