Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and catch speech computation errors, add missing braille option #1053

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@
"mathjax-modern-font": "^4.0.0-beta.4",
"mhchemparser": "^4.2.1",
"mj-context-menu": "^0.9.1",
"speech-rule-engine": "^4.1.0-beta.7"
"speech-rule-engine": "^4.1.0-beta.8"
}
}
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ts/a11y/explorer/KeyExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
return parent && this.highlighter.isMactionNode(parent) ? parent : null;
}

/**
* Computes the nesting depth announcement for the currently focused sub
* expression.
*
* @param {HTMLElement} node The current node.
* @return {HTMLElement} The refocused node.
*/
public depth(node: HTMLElement): HTMLElement {
this.generators.depth(node, !!this.actionable(node));
this.refocus(node);
Expand Down
47 changes: 18 additions & 29 deletions ts/a11y/semantic-enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,21 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
*/
public attachSpeech(document: MathDocument<N, T, D>) {
if (this.state() >= STATE.ATTACHSPEECH) return;
if (this.isEscaped || !document.options.enableEnrichment) {
this.state(STATE.ATTACHSPEECH);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do any of the calls below cause a MathJax retry error? (That is, do any call mathjax.retryAfter()?)

If not, then you can do this.state(STATE.ATTACHSPEECH) above line 247, and then just return here and the other places where the state is set. That would avoid having to set the state in several places. But it only works if the rest of the code will always complete and not restart the typesetting via retryAfter().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not. The only place that triggers a retryAfter is in line 183:

this.generatorPool.init(document.options, document.adaptor);

But that should have run before attachSpeech at all times.

return;
}
let [speech, braille] = this.existingSpeech();
let [newSpeech, newBraille] = ['', ''];
if (!speech || !braille ||
document.options.enableSpeech || document.options.enableBraille) {
[newSpeech, newBraille] = this.generatorPool.computeSpeech(
this.typesetRoot, this.toMathML(this.root, this));
if ((!speech && document.options.enableSpeech) ||
(!braille && document.options.enableBraille)) {
try {
[newSpeech, newBraille] = this.generatorPool.computeSpeech(
this.typesetRoot, this.toMathML(this.root, this));
if (newSpeech) {
newSpeech = buildSpeech(newSpeech)[0];
}
} catch (_e) { }
}
speech = speech || newSpeech;
braille = braille || newBraille;
Expand All @@ -273,29 +282,6 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
this.state(STATE.ATTACHSPEECH);
}

/**
* Retrieves the actual speech element that should be used as aria label.
* @param {MmlNode} node The root node to search from.
* @return {string} The speech content.
*/
protected getSpeech(node: MmlNode): string {
const attributes = node.attributes;
if (!attributes) return '';
const speech = attributes.getExplicit('data-semantic-speech') as string;
// TODO (explorer) For tree role move all speech etc. to container
// element.
if (!attributes.hasExplicit('data-semantic-parent') && speech) {
return speech;
}
for (let child of node.childNodes) {
let value = this.getSpeech(child);
if (value) {
return value;
}
}
return '';
}

};

}
Expand Down Expand Up @@ -359,6 +345,7 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
...BaseDocument.OPTIONS,
enableEnrichment: true,
enableSpeech: true,
enableBraille: true,
enrichError: (doc: EnrichedMathDocument<N, T, D>,
math: EnrichedMathItem<N, T, D>,
err: Error) => doc.enrichError(doc, math, err),
Expand Down Expand Up @@ -404,8 +391,10 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
*/
public attachSpeech() {
if (!this.processed.isSet('attach-speech')) {
for (const math of this.math) {
(math as EnrichedMathItem<N, T, D>).attachSpeech(this);
if (this.options.enableSpeech || this.options.enableBraille) {
for (const math of this.math) {
(math as EnrichedMathItem<N, T, D>).attachSpeech(this);
}
}
this.processed.set('attach-speech');
}
Expand Down
2 changes: 1 addition & 1 deletion ts/a11y/speech/GeneratorPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export class GeneratorPool<N, T, D> {
this.CleanUp(node);
return this.lastSpeech;
}
let postfix = this.summaryGenerator.getExpandable(
let postfix = this.summaryGenerator.getActionable(
actionable ?
(this.adaptor.childNodes(node).length === 0 ? -1 : 1)
: 0);
Expand Down