Skip to content

Commit 0b51a5f

Browse files
authored
Merge pull request #679 from mathjax/sre-errors
Add support for trapping and reporting sre errors.
2 parents 5b664e6 + 66a83dc commit 0b51a5f

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

ts/a11y/explorer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,11 @@ let csSelectionBox = function(menu: MJContextMenu, locale: string) {
643643
let csMenu = function(menu: MJContextMenu, sub: Submenu) {
644644
let locale = menu.pool.lookup('locale').getValue() as string;
645645
const box = csSelectionBox(menu, locale);
646-
const items = sre.ClearspeakPreferences.smartPreferences(
647-
menu.mathItem, locale);
646+
let items: Object[] = [];
647+
try {
648+
items = sre.ClearspeakPreferences.smartPreferences(
649+
menu.mathItem, locale);
650+
} catch (e) {}
648651
if (box) {
649652
items.splice(2, 0, box);
650653
}

ts/a11y/semantic-enrich.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,16 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
136136
currentSpeech = document.options.sre.speech;
137137
}
138138
const math = new document.options.MathItem('', MmlJax);
139-
math.math = this.serializeMml(SRE.toEnriched(toMathML(this.root)));
140-
math.display = this.display;
141-
math.compile(document);
142-
this.root = math.root;
143-
this.inputData.originalMml = math.math;
139+
try {
140+
const mml = this.inputData.originalMml = toMathML(this.root);
141+
math.math = this.serializeMml(SRE.toEnriched(mml));
142+
math.display = this.display;
143+
math.compile(document);
144+
this.root = math.root;
145+
this.inputData.enrichedMml = math.math;
146+
} catch (err) {
147+
document.options.enrichError(document, this, err);
148+
}
144149
}
145150
this.state(STATE.ENRICHED);
146151
}
@@ -213,6 +218,13 @@ export interface EnrichedMathDocument<N, T, D> extends AbstractMathDocument<N, T
213218
* @return {EnrichedMathDocument} The MathDocument (so calls can be chained)
214219
*/
215220
attachSpeech(): EnrichedMathDocument<N, T, D>;
221+
222+
/**
223+
* @param {EnrichedMathDocument} doc The MathDocument for the error
224+
* @paarm {EnrichedMathItem} math The MathItem causing the error
225+
* @param {Error} err The error being processed
226+
*/
227+
enrichError(doc: EnrichedMathDocument<N, T, D>, math: EnrichedMathItem<N, T, D>, err: Error): void;
216228
}
217229

218230
/**
@@ -240,6 +252,9 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
240252
public static OPTIONS: OptionList = {
241253
...BaseDocument.OPTIONS,
242254
enableEnrichment: true,
255+
enrichError: (doc: EnrichedMathDocument<N, T, D>,
256+
math: EnrichedMathItem<N, T, D>,
257+
err: Error) => doc.enrichError(doc, math, err),
243258
renderActions: expandable({
244259
...BaseDocument.OPTIONS.renderActions,
245260
enrich: [STATE.ENRICHED],
@@ -305,6 +320,12 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
305320
return this;
306321
}
307322

323+
/**
324+
*/
325+
public enrichError(_doc: EnrichedMathDocument<N, T, D>, _math: EnrichedMathItem<N, T, D>, err: Error) {
326+
console.warn('Enrichment error:', err);
327+
}
328+
308329
/**
309330
* @override
310331
*/

0 commit comments

Comments
 (0)