We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4d1e195 commit 7829440Copy full SHA for 7829440
7 files changed
testsuite/tests/util/FunctionList.test.ts
@@ -1,5 +1,5 @@
1
import { describe, test, expect } from '@jest/globals';
2
-import {FunctionList} from '#js/util/FunctionList.js';
+import {FunctionList, AnyFunction} from '#js/util/FunctionList.js';
3
4
//
5
// Set up a function list with 6 functions that captures output
@@ -43,6 +43,15 @@ describe('FunctionList functionality', () => {
43
expect(item).toBe(fn);
44
});
45
46
+ test('Adding a list of items', () => {
47
+ const fns = [(_: any) => {}, [(_: any) => {}, 1]] as [AnyFunction, [AnyFunction, number]];
48
+ const list = new FunctionList(fns);
49
+ expect(Array.from(list)).toEqual([
50
+ {item: fns[1][0], priority: 1},
51
+ {item: fns[0], priority: 5},
52
+ ]);
53
+ });
54
+
55
test('Removing one item', () => {
56
const list = new FunctionList();
57
const fn = list.add(FN(0));
ts/core/InputJax.ts
@@ -129,7 +129,10 @@ export abstract class AbstractInputJax<N, T, D> implements InputJax<N, T, D> {
129
/**
130
* The default options for the input jax
131
*/
132
- public static OPTIONS: OptionList = {};
+ public static OPTIONS: OptionList = {
133
+ preFilters: [],
134
+ postFilters: [],
135
+ };
136
137
138
* The actual options supplied to the input jax
@@ -163,8 +166,8 @@ export abstract class AbstractInputJax<N, T, D> implements InputJax<N, T, D> {
163
166
constructor(options: OptionList = {}) {
164
167
const CLASS = this.constructor as typeof AbstractInputJax;
165
168
this.options = userOptions(defaultOptions({}, CLASS.OPTIONS), options);
- this.preFilters = new FunctionList();
- this.postFilters = new FunctionList();
169
+ this.preFilters = new FunctionList(this.options.preFilters);
170
+ this.postFilters = new FunctionList(this.options.postFilters);
171
}
172
173
ts/core/OutputJax.ts
@@ -47,7 +47,12 @@ export interface OutputJax<N, T, D> {
options: OptionList;
- * Lists of post-filters to call after typesetting the math
+ * Lists of pre-filters to call after typesetting the math
+ */
+ preFilters: FunctionList;
+ /**
+ * Lists of post-filters to call before typesetting the math
postFilters: FunctionList;
58
@@ -130,13 +135,21 @@ export abstract class AbstractOutputJax<N, T, D> implements OutputJax<N, T, D> {
* The default options for the output jax
139
140
141
142
143
144
* The actual options supplied to the output jax
145
146
public options: OptionList;
147
148
149
+ * Filters to run before the output is processed
150
151
+ public preFilters: FunctionList;
152
153
154
* Filters to run after the output is processed
155
@@ -153,7 +166,8 @@ export abstract class AbstractOutputJax<N, T, D> implements OutputJax<N, T, D> {
const CLASS = this.constructor as typeof AbstractOutputJax;
156
157
158
159
ts/input/mathml.ts
@@ -57,6 +57,7 @@ export class MathML<N, T, D> extends AbstractInputJax<N, T, D> {
public static OPTIONS: OptionList = defaultOptions({
parseAs: 'html', // Whether to use HTML or XML parsing for the MathML string
59
forceReparse: false, // Whether to force the string to be reparsed, or use the one from the document DOM
60
+ mmlFilters: [], // Filters to add to the mmlFilters lost
61
FindMathML: null, // The FindMathML instance to override the default one
62
MathMLCompile: null, // The MathMLCompile instance to override the default one
63
/*
@@ -92,11 +93,10 @@ export class MathML<N, T, D> extends AbstractInputJax<N, T, D> {
92
93
MathMLCompile.OPTIONS
94
);
95
super(mml);
- this.findMathML =
96
- this.options['FindMathML'] || new FindMathML<N, T, D>(find);
+ this.findMathML = this.options.FindMathML || new FindMathML<N, T, D>(find);
97
this.mathml =
98
- this.options['MathMLCompile'] || new MathMLCompile<N, T, D>(compile);
99
- this.mmlFilters = new FunctionList();
+ this.options.MathMLCompile || new MathMLCompile<N, T, D>(compile);
+ this.mmlFilters = new FunctionList(this.options.mmlFilters);
100
101
102
ts/input/tex.ts
@@ -157,13 +157,15 @@ export class TeX<N, T, D> extends AbstractInputJax<N, T, D> {
userOptions(parseOptions.options, rest);
configuration.config(this);
TeX.tags(parseOptions, configuration);
160
- this.postFilters.add(FilterUtil.cleanSubSup, -7);
161
- this.postFilters.add(FilterUtil.setInherited, -6);
162
- this.postFilters.add(FilterUtil.checkScriptlevel, -5);
- this.postFilters.add(FilterUtil.moveLimits, -4);
- this.postFilters.add(FilterUtil.cleanStretchy, -3);
- this.postFilters.add(FilterUtil.cleanAttributes, -2);
- this.postFilters.add(FilterUtil.combineRelations, -1);
+ this.postFilters.addList([
+ [FilterUtil.cleanSubSup, -7],
+ [FilterUtil.setInherited, -6],
+ [FilterUtil.checkScriptlevel, -5],
+ [FilterUtil.moveLimits, -4],
+ [FilterUtil.cleanStretchy, -3],
+ [FilterUtil.cleanAttributes, -2],
+ [FilterUtil.combineRelations, -1],
ts/output/common.ts
@@ -414,6 +414,7 @@ export abstract class CommonOutputJax<
414
this.math = math;
415
this.container = node;
416
this.pxPerEm = math.metrics.ex / this.font.params.x_height;
417
+ this.executeFilters(this.preFilters, math, html, node);
418
this.nodeMap = new Map<MmlNode, WW>();
419
math.root.attributes.getAllInherited().overflow =
420
this.options.displayOverflow;
ts/util/FunctionList.ts
@@ -23,7 +23,9 @@
23
24
import { PrioritizedList, PrioritizedListItem } from './PrioritizedList.js';
25
26
-type AnyFunction = (...args: unknown[]) => unknown;
+export type AnyFunction = (...args: unknown[]) => unknown;
27
+export type AnyFunctionDef = AnyFunction | [AnyFunction, number];
28
+export type AnyFunctionList = AnyFunctionDef[];
29
30
/*****************************************************************/
31
@@ -38,6 +40,32 @@ export interface FunctionListItem extends PrioritizedListItem<AnyFunction> {}
38
40
39
41
42
export class FunctionList extends PrioritizedList<AnyFunction> {
+ * @override
+ * @param {AnyFunctionList} list The initial list of functions to add
+ constructor(list: AnyFunctionList = null) {
+ super();
+ if (list) {
+ this.addList(list);
+ }
+ * Add a list of filter functions, possibly with priorities.
+ *
+ * @param {AnyFunctionList} list The list of functions to add
+ public addList(list: AnyFunctionList) {
+ for (const item of list) {
+ if (Array.isArray(item)) {
+ this.add(item[0], item[1]);
+ } else {
64
+ this.add(item);
65
66
67
68
69
70
* Executes the functions in the list (in prioritized order),
71
* passing the given data to the functions. If any return
0 commit comments