@@ -244,19 +244,23 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
244
244
*/
245
245
public attachSpeech ( document : MathDocument < N , T , D > ) {
246
246
if ( this . state ( ) >= STATE . ATTACHSPEECH ) return ;
247
+ this . state ( STATE . ATTACHSPEECH ) ;
248
+ if ( this . isEscaped || ! document . options . enableEnrichment ) return ;
247
249
let [ speech , braille ] = this . existingSpeech ( ) ;
248
250
let [ newSpeech , newBraille ] = [ '' , '' ] ;
249
- if ( ! speech || ! braille ||
250
- document . options . enableSpeech || document . options . enableBraille ) {
251
- [ newSpeech , newBraille ] = this . generatorPool . computeSpeech (
252
- this . typesetRoot , this . toMathML ( this . root , this ) ) ;
251
+ if ( ( ! speech && document . options . enableSpeech ) ||
252
+ ( ! braille && document . options . enableBraille ) ) {
253
+ try {
254
+ [ newSpeech , newBraille ] = this . generatorPool . computeSpeech (
255
+ this . typesetRoot , this . toMathML ( this . root , this ) ) ;
256
+ if ( newSpeech ) {
257
+ newSpeech = buildSpeech ( newSpeech ) [ 0 ] ;
258
+ }
259
+ } catch ( _e ) { }
253
260
}
254
261
speech = speech || newSpeech ;
255
262
braille = braille || newBraille ;
256
- if ( ! speech && ! braille ) {
257
- this . state ( STATE . ATTACHSPEECH ) ;
258
- return ;
259
- }
263
+ if ( ! speech && ! braille ) return ;
260
264
const adaptor = document . adaptor ;
261
265
const node = this . typesetRoot ;
262
266
if ( speech ) {
@@ -270,30 +274,6 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
270
274
}
271
275
this . outputData . speech = speech ;
272
276
this . outputData . braille = braille ;
273
- this . state ( STATE . ATTACHSPEECH ) ;
274
- }
275
-
276
- /**
277
- * Retrieves the actual speech element that should be used as aria label.
278
- * @param {MmlNode } node The root node to search from.
279
- * @return {string } The speech content.
280
- */
281
- protected getSpeech ( node : MmlNode ) : string {
282
- const attributes = node . attributes ;
283
- if ( ! attributes ) return '' ;
284
- const speech = attributes . getExplicit ( 'data-semantic-speech' ) as string ;
285
- // TODO (explorer) For tree role move all speech etc. to container
286
- // element.
287
- if ( ! attributes . hasExplicit ( 'data-semantic-parent' ) && speech ) {
288
- return speech ;
289
- }
290
- for ( let child of node . childNodes ) {
291
- let value = this . getSpeech ( child ) ;
292
- if ( value ) {
293
- return value ;
294
- }
295
- }
296
- return '' ;
297
277
}
298
278
299
279
} ;
@@ -359,6 +339,7 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
359
339
...BaseDocument . OPTIONS ,
360
340
enableEnrichment : true ,
361
341
enableSpeech : true ,
342
+ enableBraille : true ,
362
343
enrichError : ( doc : EnrichedMathDocument < N , T , D > ,
363
344
math : EnrichedMathItem < N , T , D > ,
364
345
err : Error ) => doc . enrichError ( doc , math , err ) ,
@@ -404,8 +385,10 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
404
385
*/
405
386
public attachSpeech ( ) {
406
387
if ( ! this . processed . isSet ( 'attach-speech' ) ) {
407
- for ( const math of this . math ) {
408
- ( math as EnrichedMathItem < N , T , D > ) . attachSpeech ( this ) ;
388
+ if ( this . options . enableSpeech || this . options . enableBraille ) {
389
+ for ( const math of this . math ) {
390
+ ( math as EnrichedMathItem < N , T , D > ) . attachSpeech ( this ) ;
391
+ }
409
392
}
410
393
this . processed . set ( 'attach-speech' ) ;
411
394
}
0 commit comments