katex 0.16.33 → 0.16.35

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.
Files changed (124) hide show
  1. package/README.md +3 -3
  2. package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
  3. package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
  4. package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
  7. package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
  8. package/contrib/mathtex-script-type/README.md +5 -5
  9. package/contrib/mhchem/README.md +1 -1
  10. package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
  11. package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
  12. package/dist/README.md +3 -3
  13. package/dist/contrib/auto-render.js +24 -57
  14. package/dist/contrib/auto-render.min.js +1 -1
  15. package/dist/contrib/auto-render.mjs +16527 -69
  16. package/dist/contrib/copy-tex.js +23 -37
  17. package/dist/contrib/copy-tex.min.js +1 -1
  18. package/dist/contrib/copy-tex.mjs +20 -40
  19. package/dist/contrib/mathtex-script-type.js +0 -3
  20. package/dist/contrib/mathtex-script-type.mjs +16493 -4
  21. package/dist/contrib/mhchem.js +55 -303
  22. package/dist/contrib/mhchem.mjs +12619 -723
  23. package/dist/contrib/render-a11y-string.js +13 -108
  24. package/dist/contrib/render-a11y-string.min.js +1 -1
  25. package/dist/contrib/render-a11y-string.mjs +16548 -154
  26. package/dist/katex-swap.css +1 -1
  27. package/dist/katex-swap.min.css +1 -1
  28. package/dist/katex.css +1 -1
  29. package/dist/katex.js +4547 -5680
  30. package/dist/katex.min.css +1 -1
  31. package/dist/katex.min.js +1 -1
  32. package/dist/katex.mjs +4588 -6496
  33. package/{katex.js → katex.ts} +8 -5
  34. package/package.json +35 -31
  35. package/src/{Lexer.js → Lexer.ts} +1 -2
  36. package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
  37. package/src/{Namespace.js → Namespace.ts} +4 -6
  38. package/src/{Options.js → Options.ts} +7 -12
  39. package/src/{ParseError.js → ParseError.ts} +16 -26
  40. package/src/{Parser.js → Parser.ts} +68 -56
  41. package/src/{Settings.js → Settings.ts} +70 -70
  42. package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
  43. package/src/{Style.js → Style.ts} +4 -5
  44. package/src/{Token.js → Token.ts} +8 -6
  45. package/src/{buildCommon.js → buildCommon.ts} +62 -55
  46. package/src/{buildHTML.js → buildHTML.ts} +29 -25
  47. package/src/{buildMathML.js → buildMathML.ts} +15 -13
  48. package/src/{buildTree.js → buildTree.ts} +1 -2
  49. package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
  50. package/src/{defineFunction.js → defineFunction.ts} +54 -56
  51. package/src/{defineMacro.js → defineMacro.ts} +12 -13
  52. package/src/{delimiter.js → delimiter.ts} +19 -17
  53. package/src/{domTree.js → domTree.ts} +94 -103
  54. package/src/environments/{array.js → array.ts} +109 -99
  55. package/src/environments/{cd.js → cd.ts} +9 -11
  56. package/src/{environments.js → environments.ts} +0 -1
  57. package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
  58. package/src/fontMetricsData.d.ts +3 -0
  59. package/src/functions/{accent.js → accent.ts} +1 -2
  60. package/src/functions/{accentunder.js → accentunder.ts} +0 -1
  61. package/src/functions/{arrow.js → arrow.ts} +4 -6
  62. package/src/functions/{char.js → char.ts} +0 -1
  63. package/src/functions/{color.js → color.ts} +5 -6
  64. package/src/functions/{cr.js → cr.ts} +0 -1
  65. package/src/functions/{def.js → def.ts} +9 -7
  66. package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
  67. package/src/functions/{enclose.js → enclose.ts} +3 -4
  68. package/src/functions/{environment.js → environment.ts} +2 -3
  69. package/src/functions/{font.js → font.ts} +4 -4
  70. package/src/functions/{genfrac.js → genfrac.ts} +14 -15
  71. package/src/functions/{hbox.js → hbox.ts} +0 -1
  72. package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
  73. package/src/functions/{href.js → href.ts} +4 -4
  74. package/src/functions/{html.js → html.ts} +3 -3
  75. package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
  76. package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
  77. package/src/functions/{kern.js → kern.ts} +0 -1
  78. package/src/functions/{lap.js → lap.ts} +0 -1
  79. package/src/functions/{math.js → math.ts} +0 -1
  80. package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
  81. package/src/functions/{mclass.js → mclass.ts} +5 -6
  82. package/src/functions/{op.js → op.ts} +9 -11
  83. package/src/functions/{operatorname.js → operatorname.ts} +4 -7
  84. package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
  85. package/src/functions/{overline.js → overline.ts} +0 -1
  86. package/src/functions/{phantom.js → phantom.ts} +0 -1
  87. package/src/functions/{pmb.js → pmb.ts} +0 -1
  88. package/src/functions/{raisebox.js → raisebox.ts} +0 -1
  89. package/src/functions/{relax.js → relax.ts} +0 -1
  90. package/src/functions/{rule.js → rule.ts} +0 -1
  91. package/src/functions/{sizing.js → sizing.ts} +0 -1
  92. package/src/functions/{smash.js → smash.ts} +2 -4
  93. package/src/functions/{sqrt.js → sqrt.ts} +0 -1
  94. package/src/functions/{styling.js → styling.ts} +3 -3
  95. package/src/functions/{supsub.js → supsub.ts} +6 -8
  96. package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
  97. package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
  98. package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
  99. package/src/functions/{tag.js → tag.ts} +0 -2
  100. package/src/functions/{text.js → text.ts} +7 -6
  101. package/src/functions/{underline.js → underline.ts} +0 -1
  102. package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
  103. package/src/functions/{vcenter.js → vcenter.ts} +0 -2
  104. package/src/functions/{verb.js → verb.ts} +0 -1
  105. package/src/{functions.js → functions.ts} +0 -1
  106. package/src/{macros.js → macros.ts} +10 -8
  107. package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
  108. package/src/parseNode.ts +522 -0
  109. package/src/{parseTree.js → parseTree.ts} +5 -3
  110. package/src/{spacingData.js → spacingData.ts} +11 -12
  111. package/src/{stretchy.js → stretchy.ts} +7 -7
  112. package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
  113. package/src/{symbols.js → symbols.ts} +6 -6
  114. package/src/{tree.js → tree.ts} +5 -7
  115. package/src/{types.js → types.ts} +1 -2
  116. package/src/unicodeAccents.js +4 -1
  117. package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
  118. package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
  119. package/src/unicodeSymbols.js +4 -3
  120. package/src/{units.js → units.ts} +2 -4
  121. package/src/{utils.js → utils.ts} +2 -3
  122. package/src/{wide-character.js → wide-character.ts} +8 -10
  123. package/types/katex.d.ts +13 -12
  124. package/src/parseNode.js +0 -523
package/README.md CHANGED
@@ -37,13 +37,13 @@ Try out KaTeX [on the demo page](https://katex.org/#demo)!
37
37
  <!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
38
38
  <html>
39
39
  <head>
40
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/katex.min.css" integrity="sha384-fgYS3VC1089n2J3rVcEbXDHlnDLQ9B2Y1hvpQ720q1NvxCduQqT4JoGc4u2QCnzE" crossorigin="anonymous">
40
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.css" integrity="sha384-ivqLDFtpksa5L56BboxjwC/qznRo3Q35PPE7eBNewaOjoz7DkLeeLQjB1iqwDS2G" crossorigin="anonymous">
41
41
 
42
42
  <!-- The loading of KaTeX is deferred to speed up page rendering -->
43
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/katex.min.js" integrity="sha384-YPHNAPyrxGS8BNnA7Q4ommqra8WQPEjooVSLzFgwgs8OXJBvadbyvx4QpfiFurGr" crossorigin="anonymous"></script>
43
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.js" integrity="sha384-yb2kEWWHgXcdYFwDa1CrlmKXNjj1scDLN1KnPiF2Gp+CZ6RxtLoSUcUSPYmLS9IR" crossorigin="anonymous"></script>
44
44
 
45
45
  <!-- To automatically render math in text elements, include the auto-render extension: -->
46
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/auto-render.min.js" integrity="sha384-JKXHIJf8PKPyDFptuKZoUyMRQJAmQKj4B4xyOca62ebJhciMYGiDdq/9twUUWyZH" crossorigin="anonymous"
46
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/auto-render.min.js" integrity="sha384-bjyGPfbij8/NDKJhSGZNP/khQVgtHUE5exjm4Ydllo42FwIgYsdLO2lXGmRBf5Mz" crossorigin="anonymous"
47
47
  onload="renderMathInElement(document.body);"></script>
48
48
  </head>
49
49
  ...
@@ -2,11 +2,35 @@
2
2
 
3
3
  import katex from "katex";
4
4
  import splitAtDelimiters from "./splitAtDelimiters";
5
+ import type {DelimiterSpec} from "./splitAtDelimiters";
6
+
7
+ interface RenderMathInElementOptions {
8
+ delimiters?: DelimiterSpec[];
9
+ preProcess?: (math: string) => string;
10
+ ignoredTags?: string[];
11
+ ignoredClasses?: string[];
12
+ errorCallback?: (msg: string, err: Error) => void;
13
+ displayMode?: boolean;
14
+ macros?: Record<string, string>;
15
+ }
16
+
17
+ interface RenderMathInElementOptionsCopy {
18
+ delimiters: DelimiterSpec[];
19
+ preProcess?: (math: string) => string;
20
+ ignoredTags: Set<string>;
21
+ ignoredClasses: string[];
22
+ errorCallback: (msg: string, err: Error) => void;
23
+ displayMode?: boolean;
24
+ macros?: Record<string, string>;
25
+ }
5
26
 
6
27
  /* Note: optionsCopy is mutated by this method. If it is ever exposed in the
7
28
  * API, we should copy it before mutating.
8
29
  */
9
- const renderMathInText = function(text, optionsCopy) {
30
+ const renderMathInText = function(
31
+ text: string,
32
+ optionsCopy: RenderMathInElementOptionsCopy
33
+ ) {
10
34
  const data = splitAtDelimiters(text, optionsCopy.delimiters);
11
35
  if (data.length === 1 && data[0].type === 'text') {
12
36
  // There is no formula in the text.
@@ -40,7 +64,7 @@ const renderMathInText = function(text, optionsCopy) {
40
64
  "` with ",
41
65
  e
42
66
  );
43
- fragment.appendChild(document.createTextNode(data[i].rawData));
67
+ fragment.appendChild(document.createTextNode(data[i].rawData!));
44
68
  continue;
45
69
  }
46
70
  fragment.appendChild(span);
@@ -50,7 +74,10 @@ const renderMathInText = function(text, optionsCopy) {
50
74
  return fragment;
51
75
  };
52
76
 
53
- const renderElem = function(elem, optionsCopy) {
77
+ const renderElem = function(
78
+ elem: HTMLElement,
79
+ optionsCopy: RenderMathInElementOptionsCopy
80
+ ) {
54
81
  for (let i = 0; i < elem.childNodes.length; i++) {
55
82
  const childNode = elem.childNodes[i];
56
83
  if (childNode.nodeType === 3) {
@@ -58,11 +85,11 @@ const renderElem = function(elem, optionsCopy) {
58
85
  // Concatenate all sibling text nodes.
59
86
  // Webkit browsers split very large text nodes into smaller ones,
60
87
  // so the delimiters may be split across different nodes.
61
- let textContentConcat = childNode.textContent;
88
+ let textContentConcat = childNode.textContent ?? "";
62
89
  let sibling = childNode.nextSibling;
63
90
  let nSiblings = 0;
64
91
  while (sibling && (sibling.nodeType === Node.TEXT_NODE)) {
65
- textContentConcat += sibling.textContent;
92
+ textContentConcat += sibling.textContent ?? "";
66
93
  sibling = sibling.nextSibling;
67
94
  nSiblings++;
68
95
  }
@@ -70,7 +97,7 @@ const renderElem = function(elem, optionsCopy) {
70
97
  if (frag) {
71
98
  // Remove extra text nodes
72
99
  for (let j = 0; j < nSiblings; j++) {
73
- childNode.nextSibling.remove();
100
+ childNode.nextSibling!.remove();
74
101
  }
75
102
  i += frag.childNodes.length - 1;
76
103
  elem.replaceChild(frag, childNode);
@@ -81,33 +108,28 @@ const renderElem = function(elem, optionsCopy) {
81
108
  }
82
109
  } else if (childNode.nodeType === 1) {
83
110
  // Element node
84
- const className = ' ' + childNode.className + ' ';
111
+ const className = ' ' + (childNode as HTMLElement).className + ' ';
85
112
  const shouldRender = !optionsCopy.ignoredTags.has(
86
113
  childNode.nodeName.toLowerCase()) &&
87
114
  optionsCopy.ignoredClasses.every(
88
- x => !className.includes(' ' + x + ' '));
115
+ (x: string) => !className.includes(' ' + x + ' '));
89
116
 
90
117
  if (shouldRender) {
91
- renderElem(childNode, optionsCopy);
118
+ renderElem(childNode as HTMLElement, optionsCopy);
92
119
  }
93
120
  }
94
121
  // Otherwise, it's something else, and ignore it.
95
122
  }
96
123
  };
97
124
 
98
- const renderMathInElement = function(elem, options) {
125
+ const renderMathInElement = function(elem: HTMLElement, options?: RenderMathInElementOptions) {
99
126
  if (!elem) {
100
127
  throw new Error("No element provided to render");
101
128
  }
102
129
 
103
- const optionsCopy = {};
130
+ const optionsCopy: Partial<RenderMathInElementOptionsCopy> = {};
104
131
 
105
- // Object.assign(optionsCopy, option)
106
- for (const option in options) {
107
- if (options.hasOwnProperty(option)) {
108
- optionsCopy[option] = options[option];
109
- }
110
- }
132
+ Object.assign(optionsCopy, options);
111
133
 
112
134
  // default options
113
135
  optionsCopy.delimiters = optionsCopy.delimiters || [
@@ -126,7 +148,7 @@ const renderMathInElement = function(elem, options) {
126
148
 
127
149
  {left: "\\[", right: "\\]", display: true},
128
150
  ];
129
- optionsCopy.ignoredTags = new Set(optionsCopy.ignoredTags || [
151
+ optionsCopy.ignoredTags = new Set<string>(options?.ignoredTags || [
130
152
  "script", "noscript", "style", "textarea", "pre", "code", "option",
131
153
  ]);
132
154
  optionsCopy.ignoredClasses = optionsCopy.ignoredClasses || [];
@@ -136,7 +158,7 @@ const renderMathInElement = function(elem, options) {
136
158
  // math elements within a single call to `renderMathInElement`.
137
159
  optionsCopy.macros = optionsCopy.macros || {};
138
160
 
139
- renderElem(elem, optionsCopy);
161
+ renderElem(elem, optionsCopy as RenderMathInElementOptionsCopy);
140
162
  };
141
163
 
142
164
  export default renderMathInElement;
@@ -1,5 +1,19 @@
1
1
  /* eslint no-constant-condition:0 */
2
- const findEndOfMath = function(delimiter, text, startIndex) {
2
+
3
+ export interface DelimiterSpec {
4
+ left: string;
5
+ right: string;
6
+ display: boolean;
7
+ }
8
+
9
+ export interface SplitAtDelimiterData {
10
+ type: "text" | "math";
11
+ data: string;
12
+ rawData?: string;
13
+ display?: boolean;
14
+ }
15
+
16
+ const findEndOfMath = function(delimiter: string, text: string, startIndex: number): number {
3
17
  // Adapted from
4
18
  // https://github.com/Khan/perseus/blob/master/src/perseus-markdown.jsx
5
19
  let index = startIndex;
@@ -27,15 +41,15 @@ const findEndOfMath = function(delimiter, text, startIndex) {
27
41
  return -1;
28
42
  };
29
43
 
30
- const escapeRegex = function(string) {
44
+ const escapeRegex = function(string: string): string {
31
45
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
32
46
  };
33
47
 
34
48
  const amsRegex = /^\\begin{/;
35
49
 
36
- const splitAtDelimiters = function(text, delimiters) {
50
+ const splitAtDelimiters = function(text: string, delimiters: DelimiterSpec[]): SplitAtDelimiterData[] {
37
51
  let index;
38
- const data = [];
52
+ const data: SplitAtDelimiterData[] = [];
39
53
 
40
54
  const regexLeft = new RegExp(
41
55
  "(" + delimiters.map((x) => escapeRegex(x.left)).join("|") + ")"
@@ -3,10 +3,18 @@
3
3
  */
4
4
  import splitAtDelimiters from "../splitAtDelimiters";
5
5
  import renderMathInElement from "../auto-render";
6
+ import type {
7
+ DelimiterSpec,
8
+ SplitAtDelimiterData,
9
+ } from "../splitAtDelimiters";
6
10
 
7
11
  beforeEach(function() {
8
12
  expect.extend({
9
- toSplitInto: function(actual, result, delimiters) {
13
+ toSplitInto: function(
14
+ actual: string,
15
+ result: SplitAtDelimiterData[],
16
+ delimiters: DelimiterSpec[],
17
+ ) {
10
18
  const message = {
11
19
  pass: true,
12
20
  message: () => "'" + actual + "' split correctly",
@@ -29,7 +37,7 @@ beforeEach(function() {
29
37
  const correct = result[i];
30
38
 
31
39
  let good = true;
32
- let diff;
40
+ let diff = "";
33
41
 
34
42
  if (real.type !== correct.type) {
35
43
  good = false;
@@ -18,7 +18,7 @@ This extension isn't part of KaTeX proper, so the script should be separately
18
18
  included in the page.
19
19
 
20
20
  ```html
21
- <script src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/copy-tex.min.js" integrity="sha384-4AtnkmNNAumd4SsWm6GOe0/PdVSFY70Osk/iE7542AZihYLpu/z8mG5Z2YmxUaut" crossorigin="anonymous"></script>
21
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/copy-tex.min.js" integrity="sha384-Pe2JWbaShhSRT0SESJ9XLPeAsi4yrNi7r/CiH0Coq7giBjK5a6Ae7XcybE8rNlQP" crossorigin="anonymous"></script>
22
22
  ```
23
23
 
24
24
  (Note that, as of KaTeX 0.16.0, there is no longer a corresponding CSS file.)
@@ -35,5 +35,5 @@ statement with `require('katex/contrib/copy-tex/katex2tex.js')`.
35
35
 
36
36
  ECMAScript module is also available:
37
37
  ```html
38
- <script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/copy-tex.mjs" integrity="sha384-bVEnwt0PtX+1EuJoOEcm4rgTUWvb2ILTdjHfI1gUe/r5fdqrTcQaUuRdHG2DciuQ" crossorigin="anonymous"></script>
38
+ <script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/copy-tex.mjs" integrity="sha384-PTy3nbMSATx5Ifo/k1ErbnbMVEp3koLGaqTD+zBo5H0fPFue/mKr1M3//74Fu6Tf" crossorigin="anonymous"></script>
39
39
  ```
@@ -1,12 +1,10 @@
1
- // @flow
2
-
3
- import katexReplaceWithTex from './katex2tex';
1
+ import katexReplaceWithTex from "./katex2tex";
4
2
 
5
3
  // Return <div class="katex"> element containing node, or null if not found.
6
- function closestKatex(node: Node): ?Element {
4
+ function closestKatex(node: Node): Element | null | undefined {
7
5
  // If node is a Text Node, for example, go up to containing Element,
8
6
  // where we can apply the `closest` method.
9
- const element: ?Element =
7
+ const element: Element | null | undefined =
10
8
  (node instanceof Element ? node : node.parentElement);
11
9
  return element && element.closest('.katex');
12
10
  }
@@ -14,7 +12,7 @@ function closestKatex(node: Node): ?Element {
14
12
  // Global copy handler to modify behavior on/within .katex elements.
15
13
  document.addEventListener('copy', function(event: ClipboardEvent) {
16
14
  const selection = window.getSelection();
17
- if (selection.isCollapsed || !event.clipboardData) {
15
+ if (!selection || selection.isCollapsed || !event.clipboardData) {
18
16
  return; // default action OK if selection is empty or unchangeable
19
17
  }
20
18
  const clipboardData = event.clipboardData;
@@ -1,8 +1,7 @@
1
- // @flow
2
1
 
3
2
  export interface CopyDelimiters {
4
- inline: [string, string],
5
- display: [string, string],
3
+ inline: [string, string];
4
+ display: [string, string];
6
5
  }
7
6
 
8
7
  // Set these to how you want inline and display math to be delimited.
@@ -11,7 +11,7 @@ included in the page, in addition to KaTeX.
11
11
  Load the extension by adding the following line to your HTML file.
12
12
 
13
13
  ```html
14
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/mathtex-script-type.min.js" integrity="sha384-Va76RKpsqLRTaW8meIebMfcIo7cxNDc0uKaZNSuZzckwzNtDa3Xf77LciJ0CAjIC" crossorigin="anonymous"></script>
14
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/mathtex-script-type.min.js" integrity="sha384-Va76RKpsqLRTaW8meIebMfcIo7cxNDc0uKaZNSuZzckwzNtDa3Xf77LciJ0CAjIC" crossorigin="anonymous"></script>
15
15
  ```
16
16
  You can download the script and use it locally, or from a local KaTeX installation instead.
17
17
 
@@ -23,9 +23,9 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1
23
23
  <!DOCTYPE html>
24
24
  <html>
25
25
  <head>
26
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/katex.min.css" integrity="sha384-fgYS3VC1089n2J3rVcEbXDHlnDLQ9B2Y1hvpQ720q1NvxCduQqT4JoGc4u2QCnzE" crossorigin="anonymous">
27
- <script src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/katex.min.js" integrity="sha384-YPHNAPyrxGS8BNnA7Q4ommqra8WQPEjooVSLzFgwgs8OXJBvadbyvx4QpfiFurGr" crossorigin="anonymous"></script>
28
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/mathtex-script-type.min.js" integrity="sha384-Va76RKpsqLRTaW8meIebMfcIo7cxNDc0uKaZNSuZzckwzNtDa3Xf77LciJ0CAjIC" crossorigin="anonymous"></script>
26
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.css" integrity="sha384-ivqLDFtpksa5L56BboxjwC/qznRo3Q35PPE7eBNewaOjoz7DkLeeLQjB1iqwDS2G" crossorigin="anonymous">
27
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.js" integrity="sha384-yb2kEWWHgXcdYFwDa1CrlmKXNjj1scDLN1KnPiF2Gp+CZ6RxtLoSUcUSPYmLS9IR" crossorigin="anonymous"></script>
28
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/mathtex-script-type.min.js" integrity="sha384-Va76RKpsqLRTaW8meIebMfcIo7cxNDc0uKaZNSuZzckwzNtDa3Xf77LciJ0CAjIC" crossorigin="anonymous"></script>
29
29
  </head>
30
30
  <body>
31
31
  <script type="math/tex">x+\sqrt{1-x^2}</script>
@@ -35,4 +35,4 @@ Then, in the body, we use a `math/tex` script to typeset the equation `x+\sqrt{1
35
35
 
36
36
  ECMAScript module is also available:
37
37
  ```html
38
- <script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/mathtex-script-type.mjs" integrity="sha384-4EJvC5tvqq9XJxXvdD4JutBokuFw/dCe2AB4gZ9sRpwFFXECpL3qT43tmE0PkpVg" crossorigin="anonymous"></script>
38
+ <script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/mathtex-script-type.mjs" integrity="sha384-9PbfyGzfSuRx+YKdc/pFgd8XkI3lFQsUHdwWQ5mO34YVf0O3WjbUYf48yVluEYni" crossorigin="anonymous"></script>
@@ -7,7 +7,7 @@ This extension adds to KaTeX the `\ce` and `\pu` functions from the [mhchem](htt
7
7
  This extension isn't part of core KaTeX, so the script should be separately included. Write the following line into the HTML page's `<head>`. Place it *after* the line that calls `katex.js`, and if you make use of the [auto-render](https://katex.org/docs/autorender.html) extension, place it *before* the line that calls `auto-render.js`.
8
8
 
9
9
  ```html
10
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/mhchem.min.js" integrity="sha384-fB8BH//9nBzROkMUsu/Dr35jWHIbnKesUo9rW0hfEgw8mZGnkAyBAjKX9F98OVuo" crossorigin="anonymous"></script>
10
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/mhchem.min.js" integrity="sha384-fB8BH//9nBzROkMUsu/Dr35jWHIbnKesUo9rW0hfEgw8mZGnkAyBAjKX9F98OVuo" crossorigin="anonymous"></script>
11
11
  ```
12
12
 
13
13
  If you remove the `defer` attribute from this tag, then you must also remove the `defer` attribute from the `<script src="https://../katex.min.js">` tag.
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * renderA11yString returns a readable string.
4
3
  *
@@ -20,11 +19,8 @@
20
19
  import type {Atom} from "../../src/symbols";
21
20
  import type {AnyParseNode} from "../../src/parseNode";
22
21
  import type {SettingsOptions} from "../../src/Settings";
23
-
24
- // $FlowIgnore: we import the types directly anyways
25
22
  import katex from "katex";
26
-
27
- const stringMap = {
23
+ const stringMap: Record<string, string> = {
28
24
  "(": "left parenthesis",
29
25
  ")": "right parenthesis",
30
26
  "[": "open bracket",
@@ -97,26 +93,22 @@ const stringMap = {
97
93
  "\\hat": "hat",
98
94
  "\\acute": "acute",
99
95
  };
100
-
101
- const powerMap = {
96
+ const powerMap: Record<string, string> = {
102
97
  "prime": "prime",
103
98
  "degree": "degrees",
104
99
  "circle": "degrees",
105
100
  "2": "squared",
106
101
  "3": "cubed",
107
102
  };
108
-
109
- const openMap = {
103
+ const openMap: Record<string, string> = {
110
104
  "|": "open vertical bar",
111
105
  ".": "",
112
106
  };
113
-
114
- const closeMap = {
107
+ const closeMap: Record<string, string> = {
115
108
  "|": "close vertical bar",
116
109
  ".": "",
117
110
  };
118
-
119
- const binMap = {
111
+ const binMap: Record<string, string> = {
120
112
  "+": "plus",
121
113
  "-": "minus",
122
114
  "\\pm": "plus minus",
@@ -128,8 +120,7 @@ const binMap = {
128
120
  "\\circ": "circle",
129
121
  "\\bullet": "bullet",
130
122
  };
131
-
132
- const relMap = {
123
+ const relMap: Record<string, string> = {
133
124
  "=": "equals",
134
125
  "\\approx": "approximately equals",
135
126
  "≠": "does not equal",
@@ -145,8 +136,7 @@ const relMap = {
145
136
  "\\Rightarrow": "right arrow",
146
137
  ":": "colon",
147
138
  };
148
-
149
- const accentUnderMap = {
139
+ const accentUnderMap: Record<string, string> = {
150
140
  "\\underleftarrow": "left arrow",
151
141
  "\\underrightarrow": "right arrow",
152
142
  "\\underleftrightarrow": "left-right arrow",
@@ -154,7 +144,6 @@ const accentUnderMap = {
154
144
  "\\underlinesegment": "line segment",
155
145
  "\\utilde": "tilde",
156
146
  };
157
-
158
147
  type NestedArray<T> = Array<T | NestedArray<T>>;
159
148
 
160
149
  const buildString = (
@@ -183,14 +172,12 @@ const buildString = (
183
172
  // If the text to add is a number and there is already a string
184
173
  // in the list and the last string is a number then we should
185
174
  // combine them into a single number
175
+ const last = a11yStrings[a11yStrings.length - 1];
186
176
  if (
187
177
  /^\d+$/.test(ret) &&
188
178
  a11yStrings.length > 0 &&
189
- // TODO(kevinb): check that the last item in a11yStrings is a string
190
- // I think we might be able to drop the nested arrays, which would make
191
- // this easier to type
192
- // $FlowFixMe
193
- /^\d+$/.test(a11yStrings[a11yStrings.length - 1])
179
+ typeof last === "string" &&
180
+ /^\d+$/.test(last)
194
181
  ) {
195
182
  a11yStrings[a11yStrings.length - 1] += ret;
196
183
  } else if (ret) {
@@ -268,7 +255,7 @@ const handleObject = (
268
255
  break;
269
256
  }
270
257
  default: {
271
- (tree.family: empty);
258
+ (tree.family as never);
272
259
  throw new Error(`"${tree.family}" is not a valid atom type`);
273
260
  }
274
261
  }
@@ -664,8 +651,8 @@ const handleObject = (
664
651
  // \neq and \ne are macros so we let "htmlmathml" render the mathmal
665
652
  // side of things and extract the text from that.
666
653
  const atomType = tree.mclass.slice(1);
667
- // $FlowFixMe: drop the leading "m" from the values in mclass
668
- buildA11yStrings(tree.body, a11yStrings, atomType);
654
+ // TODO(ts): drop the leading "m" from the values in mclass
655
+ buildA11yStrings(tree.body, a11yStrings, atomType as Atom | "normal");
669
656
  break;
670
657
  }
671
658
 
@@ -697,8 +684,7 @@ const handleObject = (
697
684
  }
698
685
 
699
686
  default:
700
- (tree.type: empty);
701
- throw new Error("KaTeX a11y un-recognized type: " + tree.type);
687
+ throw new Error("KaTeX a11y un-recognized type: " + (tree as AnyParseNode).type);
702
688
  }
703
689
  };
704
690
 
@@ -718,12 +704,11 @@ const buildA11yStrings = (
718
704
  return a11yStrings;
719
705
  };
720
706
 
721
-
722
- const flatten = function(array) {
723
- let result = [];
707
+ const flatten = function(array: NestedArray<string>): string[] {
708
+ let result: string[] = [];
724
709
 
725
710
  array.forEach(function(item) {
726
- if (item instanceof Array) {
711
+ if (Array.isArray(item)) {
727
712
  result = result.concat(flatten(item));
728
713
  } else {
729
714
  result.push(item);
@@ -737,9 +722,9 @@ const renderA11yString = function(
737
722
  text: string,
738
723
  settings?: SettingsOptions,
739
724
  ): string {
740
-
741
725
  const tree = katex.__parse(text, settings);
742
726
  const a11yStrings = buildA11yStrings(tree, [], "normal");
727
+
743
728
  return flatten(a11yStrings).join(", ");
744
729
  };
745
730
 
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable max-len */
2
- // @flow
3
2
  import renderA11yString from "../render-a11y-string";
4
3
 
5
4
  describe("renderA11yString", () => {
package/dist/README.md CHANGED
@@ -37,13 +37,13 @@ Try out KaTeX [on the demo page](https://katex.org/#demo)!
37
37
  <!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
38
38
  <html>
39
39
  <head>
40
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/katex.min.css" integrity="sha384-fgYS3VC1089n2J3rVcEbXDHlnDLQ9B2Y1hvpQ720q1NvxCduQqT4JoGc4u2QCnzE" crossorigin="anonymous">
40
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.css" integrity="sha384-ivqLDFtpksa5L56BboxjwC/qznRo3Q35PPE7eBNewaOjoz7DkLeeLQjB1iqwDS2G" crossorigin="anonymous">
41
41
 
42
42
  <!-- The loading of KaTeX is deferred to speed up page rendering -->
43
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/katex.min.js" integrity="sha384-YPHNAPyrxGS8BNnA7Q4ommqra8WQPEjooVSLzFgwgs8OXJBvadbyvx4QpfiFurGr" crossorigin="anonymous"></script>
43
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.js" integrity="sha384-yb2kEWWHgXcdYFwDa1CrlmKXNjj1scDLN1KnPiF2Gp+CZ6RxtLoSUcUSPYmLS9IR" crossorigin="anonymous"></script>
44
44
 
45
45
  <!-- To automatically render math in text elements, include the auto-render extension: -->
46
- <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.33/dist/contrib/auto-render.min.js" integrity="sha384-JKXHIJf8PKPyDFptuKZoUyMRQJAmQKj4B4xyOca62ebJhciMYGiDdq/9twUUWyZH" crossorigin="anonymous"
46
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/contrib/auto-render.min.js" integrity="sha384-bjyGPfbij8/NDKJhSGZNP/khQVgtHUE5exjm4Ydllo42FwIgYsdLO2lXGmRBf5Mz" crossorigin="anonymous"
47
47
  onload="renderMathInElement(document.body);"></script>
48
48
  </head>
49
49
  ...