katex 0.14.0 → 0.14.1

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
@@ -260,7 +260,126 @@ var utils = {
260
260
  };
261
261
 
262
262
  /* eslint no-console:0 */
263
+ // TODO: automatically generate documentation
264
+ // TODO: check all properties on Settings exist
265
+ // TODO: check the type of a property on Settings matches
266
+ var SETTINGS_SCHEMA = {
267
+ displayMode: {
268
+ type: "boolean",
269
+ description: "Render math in display mode, which puts the math in " + "display style (so \\int and \\sum are large, for example), and " + "centers the math on the page on its own line.",
270
+ cli: "-d, --display-mode"
271
+ },
272
+ output: {
273
+ type: {
274
+ enum: ["htmlAndMathml", "html", "mathml"]
275
+ },
276
+ description: "Determines the markup language of the output.",
277
+ cli: "-F, --format <type>"
278
+ },
279
+ leqno: {
280
+ type: "boolean",
281
+ description: "Render display math in leqno style (left-justified tags)."
282
+ },
283
+ fleqn: {
284
+ type: "boolean",
285
+ description: "Render display math flush left."
286
+ },
287
+ throwOnError: {
288
+ type: "boolean",
289
+ default: true,
290
+ cli: "-t, --no-throw-on-error",
291
+ cliDescription: "Render errors (in the color given by --error-color) ins" + "tead of throwing a ParseError exception when encountering an error."
292
+ },
293
+ errorColor: {
294
+ type: "string",
295
+ default: "#cc0000",
296
+ cli: "-c, --error-color <color>",
297
+ cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " + "(no #). This option determines the color of errors rendered by the " + "-t option.",
298
+ cliProcessor: color => "#" + color
299
+ },
300
+ macros: {
301
+ type: "object",
302
+ cli: "-m, --macro <def>",
303
+ cliDescription: "Define custom macro of the form '\\foo:expansion' (use " + "multiple -m arguments for multiple macros).",
304
+ cliDefault: [],
305
+ cliProcessor: (def, defs) => {
306
+ defs.push(def);
307
+ return defs;
308
+ }
309
+ },
310
+ minRuleThickness: {
311
+ type: "number",
312
+ description: "Specifies a minimum thickness, in ems, for fraction lines," + " `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, " + "`\\hdashline`, `\\underline`, `\\overline`, and the borders of " + "`\\fbox`, `\\boxed`, and `\\fcolorbox`.",
313
+ processor: t => Math.max(0, t),
314
+ cli: "--min-rule-thickness <size>",
315
+ cliProcessor: parseFloat
316
+ },
317
+ colorIsTextColor: {
318
+ type: "boolean",
319
+ description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " + "instead of LaTeX's one-argument \\color mode change.",
320
+ cli: "-b, --color-is-text-color"
321
+ },
322
+ strict: {
323
+ type: [{
324
+ enum: ["warn", "ignore", "error"]
325
+ }, "boolean", "function"],
326
+ description: "Turn on strict / LaTeX faithfulness mode, which throws an " + "error if the input uses features that are not supported by LaTeX.",
327
+ cli: "-S, --strict",
328
+ cliDefault: false
329
+ },
330
+ trust: {
331
+ type: ["boolean", "function"],
332
+ description: "Trust the input, enabling all HTML features such as \\url.",
333
+ cli: "-T, --trust"
334
+ },
335
+ maxSize: {
336
+ type: "number",
337
+ default: Infinity,
338
+ description: "If non-zero, all user-specified sizes, e.g. in " + "\\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, " + "elements and spaces can be arbitrarily large",
339
+ processor: s => Math.max(0, s),
340
+ cli: "-s, --max-size <n>",
341
+ cliProcessor: parseInt
342
+ },
343
+ maxExpand: {
344
+ type: "number",
345
+ default: 1000,
346
+ description: "Limit the number of macro expansions to the specified " + "number, to prevent e.g. infinite macro loops. If set to Infinity, " + "the macro expander will try to fully expand as in LaTeX.",
347
+ processor: n => Math.max(0, n),
348
+ cli: "-e, --max-expand <n>",
349
+ cliProcessor: n => n === "Infinity" ? Infinity : parseInt(n)
350
+ },
351
+ globalGroup: {
352
+ type: "boolean",
353
+ cli: false
354
+ }
355
+ };
356
+
357
+ function getDefaultValue(schema) {
358
+ if (schema.default) {
359
+ return schema.default;
360
+ }
361
+
362
+ var type = schema.type;
363
+ var defaultType = Array.isArray(type) ? type[0] : type;
263
364
 
365
+ if (typeof defaultType !== 'string') {
366
+ return defaultType.enum[0];
367
+ }
368
+
369
+ switch (defaultType) {
370
+ case 'boolean':
371
+ return false;
372
+
373
+ case 'string':
374
+ return '';
375
+
376
+ case 'number':
377
+ return 0;
378
+
379
+ case 'object':
380
+ return {};
381
+ }
382
+ }
264
383
  /**
265
384
  * The main Settings object
266
385
  *
@@ -271,6 +390,8 @@ var utils = {
271
390
  * math (true), meaning that the math starts in \displaystyle
272
391
  * and is placed in a block with vertical margin.
273
392
  */
393
+
394
+
274
395
  class Settings {
275
396
  constructor(options) {
276
397
  this.displayMode = void 0;
@@ -289,20 +410,16 @@ class Settings {
289
410
  this.globalGroup = void 0;
290
411
  // allow null options
291
412
  options = options || {};
292
- this.displayMode = utils.deflt(options.displayMode, false);
293
- this.output = utils.deflt(options.output, "htmlAndMathml");
294
- this.leqno = utils.deflt(options.leqno, false);
295
- this.fleqn = utils.deflt(options.fleqn, false);
296
- this.throwOnError = utils.deflt(options.throwOnError, true);
297
- this.errorColor = utils.deflt(options.errorColor, "#cc0000");
298
- this.macros = options.macros || {};
299
- this.minRuleThickness = Math.max(0, utils.deflt(options.minRuleThickness, 0));
300
- this.colorIsTextColor = utils.deflt(options.colorIsTextColor, false);
301
- this.strict = utils.deflt(options.strict, "warn");
302
- this.trust = utils.deflt(options.trust, false);
303
- this.maxSize = Math.max(0, utils.deflt(options.maxSize, Infinity));
304
- this.maxExpand = Math.max(0, utils.deflt(options.maxExpand, 1000));
305
- this.globalGroup = utils.deflt(options.globalGroup, false);
413
+
414
+ for (var prop in SETTINGS_SCHEMA) {
415
+ if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
416
+ // $FlowFixMe
417
+ var schema = SETTINGS_SCHEMA[prop]; // TODO: validate options
418
+ // $FlowFixMe
419
+
420
+ this[prop] = options[prop] !== undefined ? schema.processor ? schema.processor(options[prop]) : options[prop] : getDefaultValue(schema);
421
+ }
422
+ }
306
423
  }
307
424
  /**
308
425
  * Report nonstrict (non-LaTeX-compatible) input.
@@ -17746,7 +17863,7 @@ var katex = {
17746
17863
  /**
17747
17864
  * Current KaTeX version
17748
17865
  */
17749
- version: "0.14.0",
17866
+ version: "0.14.1",
17750
17867
 
17751
17868
  /**
17752
17869
  * Renders the given LaTeX into an HTML+MathML combination, and adds
@@ -17765,6 +17882,11 @@ var katex = {
17765
17882
  */
17766
17883
  ParseError,
17767
17884
 
17885
+ /**
17886
+ * The shema of Settings
17887
+ */
17888
+ SETTINGS_SCHEMA,
17889
+
17768
17890
  /**
17769
17891
  * Parses the given LaTeX into KaTeX's internal parse tree structure,
17770
17892
  * without rendering to HTML or MathML.
package/katex.js CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
 
11
11
  import ParseError from "./src/ParseError";
12
- import Settings from "./src/Settings";
12
+ import Settings, {SETTINGS_SCHEMA} from "./src/Settings";
13
13
 
14
14
  import {buildTree, buildHTMLTree} from "./src/buildTree";
15
15
  import parseTree from "./src/parseTree";
@@ -156,6 +156,10 @@ export default {
156
156
  * KaTeX error, usually during parsing.
157
157
  */
158
158
  ParseError,
159
+ /**
160
+ * The shema of Settings
161
+ */
162
+ SETTINGS_SCHEMA,
159
163
  /**
160
164
  * Parses the given LaTeX into KaTeX's internal parse tree structure,
161
165
  * without rendering to HTML or MathML.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
package/src/Settings.js CHANGED
@@ -52,23 +52,180 @@ export type TrustContextTypes = {
52
52
  export type AnyTrustContext = $Values<TrustContextTypes>;
53
53
  export type TrustFunction = (context: AnyTrustContext) => ?boolean;
54
54
 
55
- export type SettingsOptions = {
56
- displayMode?: boolean;
57
- output?: "html" | "mathml" | "htmlAndMathml";
58
- leqno?: boolean;
59
- fleqn?: boolean;
60
- throwOnError?: boolean;
61
- errorColor?: string;
62
- macros?: MacroMap;
63
- minRuleThickness?: number;
64
- colorIsTextColor?: boolean;
65
- strict?: boolean | "ignore" | "warn" | "error" | StrictFunction;
66
- trust?: boolean | TrustFunction;
67
- maxSize?: number;
68
- maxExpand?: number;
69
- globalGroup?: boolean;
55
+ export type SettingsOptions = $Shape<Settings>;
56
+
57
+ type EnumType = {| enum: string[] |};
58
+ type Type = "boolean" | "string" | "number" | "object" | "function" | EnumType;
59
+ type Schema = {
60
+ [$Keys<SettingsOptions>]: {
61
+ /**
62
+ * Allowed type(s) of the value.
63
+ */
64
+ type: Type | Type[];
65
+ /**
66
+ * The default value. If not specified, false for boolean, an empty string
67
+ * for string, 0 for number, an empty object for object, or the first item
68
+ * for enum will be used. If multiple types are allowed, the first allowed
69
+ * type will be used for determining the default value.
70
+ */
71
+ default?: any;
72
+ /**
73
+ * The description.
74
+ */
75
+ description?: string;
76
+ /**
77
+ * The function to process the option.
78
+ */
79
+ processor?: (any) => any,
80
+ /**
81
+ * The command line argument. See Commander.js docs for more information.
82
+ * If not specified, the name prefixed with -- will be used. Set false not
83
+ * to add to the CLI.
84
+ */
85
+ cli?: string | false;
86
+ /**
87
+ * The default value for the CLI.
88
+ */
89
+ cliDefault?: any;
90
+ /**
91
+ * The description for the CLI. If not specified, the description for the
92
+ * option will be used.
93
+ */
94
+ cliDescription?: string;
95
+ /**
96
+ * The custom argument processor for the CLI. See Commander.js docs for
97
+ * more information.
98
+ */
99
+ cliProcessor?: (any, any) => any;
100
+ };
101
+ };
102
+
103
+ // TODO: automatically generate documentation
104
+ // TODO: check all properties on Settings exist
105
+ // TODO: check the type of a property on Settings matches
106
+ export const SETTINGS_SCHEMA: Schema = {
107
+ displayMode: {
108
+ type: "boolean",
109
+ description: "Render math in display mode, which puts the math in " +
110
+ "display style (so \\int and \\sum are large, for example), and " +
111
+ "centers the math on the page on its own line.",
112
+ cli: "-d, --display-mode",
113
+ },
114
+ output: {
115
+ type: {enum: ["htmlAndMathml", "html", "mathml"]},
116
+ description: "Determines the markup language of the output.",
117
+ cli: "-F, --format <type>",
118
+ },
119
+ leqno: {
120
+ type: "boolean",
121
+ description: "Render display math in leqno style (left-justified tags).",
122
+ },
123
+ fleqn: {
124
+ type: "boolean",
125
+ description: "Render display math flush left.",
126
+ },
127
+ throwOnError: {
128
+ type: "boolean",
129
+ default: true,
130
+ cli: "-t, --no-throw-on-error",
131
+ cliDescription: "Render errors (in the color given by --error-color) ins" +
132
+ "tead of throwing a ParseError exception when encountering an error.",
133
+ },
134
+ errorColor: {
135
+ type: "string",
136
+ default: "#cc0000",
137
+ cli: "-c, --error-color <color>",
138
+ cliDescription: "A color string given in the format 'rgb' or 'rrggbb' " +
139
+ "(no #). This option determines the color of errors rendered by the " +
140
+ "-t option.",
141
+ cliProcessor: (color) => "#" + color,
142
+ },
143
+ macros: {
144
+ type: "object",
145
+ cli: "-m, --macro <def>",
146
+ cliDescription: "Define custom macro of the form '\\foo:expansion' (use " +
147
+ "multiple -m arguments for multiple macros).",
148
+ cliDefault: [],
149
+ cliProcessor: (def, defs) => {
150
+ defs.push(def);
151
+ return defs;
152
+ },
153
+ },
154
+ minRuleThickness: {
155
+ type: "number",
156
+ description: "Specifies a minimum thickness, in ems, for fraction lines," +
157
+ " `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, " +
158
+ "`\\hdashline`, `\\underline`, `\\overline`, and the borders of " +
159
+ "`\\fbox`, `\\boxed`, and `\\fcolorbox`.",
160
+ processor: (t) => Math.max(0, t),
161
+ cli: "--min-rule-thickness <size>",
162
+ cliProcessor: parseFloat,
163
+ },
164
+ colorIsTextColor: {
165
+ type: "boolean",
166
+ description: "Makes \\color behave like LaTeX's 2-argument \\textcolor, " +
167
+ "instead of LaTeX's one-argument \\color mode change.",
168
+ cli: "-b, --color-is-text-color",
169
+ },
170
+ strict: {
171
+ type: [{enum: ["warn", "ignore", "error"]}, "boolean", "function"],
172
+ description: "Turn on strict / LaTeX faithfulness mode, which throws an " +
173
+ "error if the input uses features that are not supported by LaTeX.",
174
+ cli: "-S, --strict",
175
+ cliDefault: false,
176
+ },
177
+ trust: {
178
+ type: ["boolean", "function"],
179
+ description: "Trust the input, enabling all HTML features such as \\url.",
180
+ cli: "-T, --trust",
181
+ },
182
+ maxSize: {
183
+ type: "number",
184
+ default: Infinity,
185
+ description: "If non-zero, all user-specified sizes, e.g. in " +
186
+ "\\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, " +
187
+ "elements and spaces can be arbitrarily large",
188
+ processor: (s) => Math.max(0, s),
189
+ cli: "-s, --max-size <n>",
190
+ cliProcessor: parseInt,
191
+ },
192
+ maxExpand: {
193
+ type: "number",
194
+ default: 1000,
195
+ description: "Limit the number of macro expansions to the specified " +
196
+ "number, to prevent e.g. infinite macro loops. If set to Infinity, " +
197
+ "the macro expander will try to fully expand as in LaTeX.",
198
+ processor: (n) => Math.max(0, n),
199
+ cli: "-e, --max-expand <n>",
200
+ cliProcessor: (n) => (n === "Infinity" ? Infinity : parseInt(n)),
201
+ },
202
+ globalGroup: {
203
+ type: "boolean",
204
+ cli: false,
205
+ },
70
206
  };
71
207
 
208
+ function getDefaultValue(schema): any {
209
+ if (schema.default) {
210
+ return schema.default;
211
+ }
212
+ const type = schema.type;
213
+ const defaultType = Array.isArray(type) ? type[0] : type;
214
+ if (typeof defaultType !== 'string') {
215
+ return defaultType.enum[0];
216
+ }
217
+ switch (defaultType) {
218
+ case 'boolean':
219
+ return false;
220
+ case 'string':
221
+ return '';
222
+ case 'number':
223
+ return 0;
224
+ case 'object':
225
+ return {};
226
+ }
227
+ }
228
+
72
229
  /**
73
230
  * The main Settings object
74
231
  *
@@ -98,23 +255,17 @@ export default class Settings {
98
255
  constructor(options: SettingsOptions) {
99
256
  // allow null options
100
257
  options = options || {};
101
- this.displayMode = utils.deflt(options.displayMode, false);
102
- this.output = utils.deflt(options.output, "htmlAndMathml");
103
- this.leqno = utils.deflt(options.leqno, false);
104
- this.fleqn = utils.deflt(options.fleqn, false);
105
- this.throwOnError = utils.deflt(options.throwOnError, true);
106
- this.errorColor = utils.deflt(options.errorColor, "#cc0000");
107
- this.macros = options.macros || {};
108
- this.minRuleThickness = Math.max(
109
- 0,
110
- utils.deflt(options.minRuleThickness, 0)
111
- );
112
- this.colorIsTextColor = utils.deflt(options.colorIsTextColor, false);
113
- this.strict = utils.deflt(options.strict, "warn");
114
- this.trust = utils.deflt(options.trust, false);
115
- this.maxSize = Math.max(0, utils.deflt(options.maxSize, Infinity));
116
- this.maxExpand = Math.max(0, utils.deflt(options.maxExpand, 1000));
117
- this.globalGroup = utils.deflt(options.globalGroup, false);
258
+ for (const prop in SETTINGS_SCHEMA) {
259
+ if (SETTINGS_SCHEMA.hasOwnProperty(prop)) {
260
+ // $FlowFixMe
261
+ const schema = SETTINGS_SCHEMA[prop];
262
+ // TODO: validate options
263
+ // $FlowFixMe
264
+ this[prop] = options[prop] !== undefined ? (schema.processor
265
+ ? schema.processor(options[prop]) : options[prop])
266
+ : getDefaultValue(schema);
267
+ }
268
+ }
118
269
  }
119
270
 
120
271
  /**