Skip to content

Commit a5b231c

Browse files
committed
Remove addEventHandlers() in favor of output jax postFilter hooks.
1 parent 6b7de34 commit a5b231c

File tree

9 files changed

+37
-43
lines changed

9 files changed

+37
-43
lines changed

lib/Mml-lab.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Lab = window.Lab = {
2929
handleRetriesFor(function () {
3030
math.compile();
3131
math.typeset(doc);
32-
}).then(() => Lab.Update(math.typesetRoot.outerHTML))
32+
}).then(() => Lab.Update(math.typesetRoot))
3333
.catch(err => {console.log("Error: "+err.message); console.log(err.stack)});
3434
},
3535

@@ -38,7 +38,8 @@ const Lab = window.Lab = {
3838
},
3939

4040
Update(html) {
41-
this.output.innerHTML = html;
41+
this.output.innerHTML = '';
42+
this.output.appendChild(html);
4243
},
4344

4445
checkKey: function (textarea, event) {

lib/TeX-lab.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Lab = window.Lab = {
2929
handleRetriesFor(function () {
3030
math.compile();
3131
math.typeset(doc);
32-
}).then(() => Lab.Update(math.typesetRoot.outerHTML))
32+
}).then(() => Lab.Update(math.typesetRoot))
3333
.catch(err => {console.log("Error: "+err.message); console.log(err.stack)});
3434
},
3535

@@ -38,7 +38,8 @@ const Lab = window.Lab = {
3838
},
3939

4040
Update(html) {
41-
this.output.innerHTML = html;
41+
this.output.innerHTML = '';
42+
this.output.appendChild(html);
4243
},
4344

4445
setDisplay(checked) {

mathjax3-ts/core/MathDocument.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import {DOMAdaptor} from '../core/DOMAdaptor.js';
4444
* .compile()
4545
* .getMetrics()
4646
* .typeset()
47-
* .addEventHandlers()
4847
* .updateDocument();
4948
*
5049
* The MathDocument is the main interface for page authors to
@@ -129,13 +128,6 @@ export interface MathDocument<N, T, D> {
129128
*/
130129
typeset(): MathDocument<N, T, D>;
131130

132-
/*
133-
* Add any event handlers to the typeset math
134-
*
135-
* @return{MathDocument} The math document instance
136-
*/
137-
addEventHandlers(): MathDocument<N, T, D>;
138-
139131
/*
140132
* Updates the document to include the typeset math
141133
*
@@ -198,7 +190,6 @@ export type MathProcessed = {
198190
compile: boolean;
199191
getMetrics: boolean;
200192
typeset: boolean;
201-
addEventHandlers: boolean;
202193
updateDocument: boolean;
203194
[name: string]: boolean;
204195
};
@@ -289,7 +280,6 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
289280
compile: false,
290281
typeset: false,
291282
getMetrics: false,
292-
addEventHandlers: false,
293283
updateDocument: false
294284
};
295285
this.outputJax = this.options['OutputJax'] || new DefaultOutputJax<N, T, D>();
@@ -405,14 +395,6 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
405395
return this;
406396
}
407397

408-
/*
409-
* @override
410-
*/
411-
public addEventHandlers() {
412-
this.processed.addEventHandlers = true;
413-
return this;
414-
}
415-
416398
/*
417399
* @override
418400
*/
@@ -445,7 +427,6 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
445427
}
446428
if (state < STATE.TYPESET) {
447429
this.processed.typeset = false;
448-
this.processed.addEventHandlers = false;
449430
this.processed.getMetrics = false;
450431
}
451432
if (state < STATE.COMPILED) {

mathjax3-ts/core/MathItem.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ export interface MathItem<N, T, D> {
149149
*/
150150
typeset(document: MathDocument<N, T, D>): void;
151151

152-
/*
153-
* Adds any needed event handlers to the typeset output
154-
*/
155-
addEventHandlers(): void;
156-
157152
/*
158153
* Inserts the typeset version in place of the original form in the document
159154
*
@@ -308,11 +303,6 @@ export abstract class AbstractMathItem<N, T, D> implements MathItem<N, T, D> {
308303
}
309304
}
310305

311-
/*
312-
* @override
313-
*/
314-
public addEventHandlers() {}
315-
316306
/*
317307
* @override
318308
*/

mathjax3-ts/core/OutputJax.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {userOptions, defaultOptions, OptionList} from '../util/Options.js';
2525
import {MathDocument} from './MathDocument.js';
2626
import {MathItem, Metrics} from './MathItem.js';
2727
import {DOMAdaptor} from '../core/DOMAdaptor.js';
28+
import {FunctionList} from '../util/FunctionList.js';
2829

2930
/*****************************************************************/
3031
/*
@@ -47,6 +48,11 @@ export interface OutputJax<N, T, D> {
4748
*/
4849
options: OptionList;
4950

51+
/*
52+
* Lists of post-filters to call after typesetting the math
53+
*/
54+
postFilters: FunctionList;
55+
5056
/*
5157
* The DOM adaptor for managing HTML elements
5258
*/
@@ -107,6 +113,7 @@ export abstract class AbstractOutputJax<N, T, D> implements OutputJax<N, T, D> {
107113
public static OPTIONS: OptionList = {};
108114

109115
public options: OptionList;
116+
public postFilters: FunctionList;
110117
public adaptor: DOMAdaptor<N, T, D> = null; // set by the handler
111118

112119
/*
@@ -115,6 +122,7 @@ export abstract class AbstractOutputJax<N, T, D> implements OutputJax<N, T, D> {
115122
constructor(options: OptionList = {}) {
116123
let CLASS = this.constructor as typeof AbstractOutputJax;
117124
this.options = userOptions(defaultOptions({}, CLASS.OPTIONS), options);
125+
this.postFilters = new FunctionList();
118126
}
119127

120128
/*
@@ -154,4 +162,19 @@ export abstract class AbstractOutputJax<N, T, D> implements OutputJax<N, T, D> {
154162
return null as N;
155163
}
156164

165+
/*
166+
* Execute a set of filters, passing them the MathItem and any needed data,
167+
* and return the (possibly modified) data
168+
*
169+
* @param{FunctionList} filters The list of functions to be performed
170+
* @param{MathItem} math The math item that is being processed
171+
* @param{any} data Whatever other data is needed
172+
* @return{any} The (possibly modidied) data
173+
*/
174+
protected executeFilters(filters: FunctionList, math: MathItem<N, T, D>, data: any) {
175+
let args = {math: math, data: data};
176+
filters.execute(args);
177+
return args.data;
178+
}
179+
157180
}

mathjax3-ts/handlers/html/HTMLDocument.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ export class HTMLDocument<N, T, D> extends AbstractMathDocument<N, T, D> {
183183
return this;
184184
}
185185

186+
/*
187+
* @param{N} head The document <head>
188+
* @param{string} id The id of the stylesheet to find
189+
* @param{N|null} The stylesheet with the given ID
190+
*/
186191
protected findSheet(head: N, id: string) {
187192
if (id) {
188193
for (const sheet of this.adaptor.tags(head, 'style')) {

mathjax3-ts/handlers/html/HTMLMathItem.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ export class HTMLMathItem<N, T, D> extends AbstractMathItem<N, T, D> {
5656
super(math, jax, display, start, end);
5757
}
5858

59-
/*
60-
* Not yet implemented
61-
*
62-
* @override
63-
*/
64-
public addEventHandlers() {}
65-
6659
/*
6760
* Insert the typeset MathItem into the document at the right location
6861
* If the starting and ending nodes are the same:

mathjax3-ts/output/chtml.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {FontData} from './chtml/FontData.js';
3232
import {TeXFont} from './chtml/fonts/tex.js';
3333
import {CssStyles} from './chtml/CssStyles.js';
3434
import {percent} from '../util/lengths.js';
35+
import {FunctionList} from '../util/FunctionList.js';
3536
import {BBox} from './chtml/BBox.js';
3637

3738

@@ -117,7 +118,7 @@ export class CHTML<N, T, D> extends AbstractOutputJax<N, T, D> {
117118
this.nodeMap = new Map<MmlNode, CHTMLWrapper<N, T, D>>();
118119
this.toCHTML(math.root, node);
119120
this.nodeMap = null;
120-
return node;
121+
return this.executeFilters(this.postFilters, math, node);
121122
}
122123

123124
/*
@@ -148,7 +149,7 @@ export class CHTML<N, T, D> extends AbstractOutputJax<N, T, D> {
148149
*/
149150
public getMetrics(html: MathDocument<N, T, D>) {
150151
for (const math of html.math) {
151-
math.setMetrics(16, 8, 1000000, 1000000, 1);
152+
math.setMetrics(16, 8, 80 * 16, 1000000, 1);
152153
}
153154
}
154155

mathjax3-ts/util/Retries.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export interface RetryError extends Error {
5555
* .compile()
5656
* .getMetrics()
5757
* .typeset()
58-
* .addEventHandlers()
5958
* .updateDocument();
6059
*
6160
* }).catch(err => {

0 commit comments

Comments
 (0)