Skip to content

Commit 2dc6a38

Browse files
committed
Incorporates review suggestions.
1 parent 53ead2a commit 2dc6a38

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

speech/action.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require('mathjax-full/js/util/asyncLoad/node.js');
2-
// This is loaded to import `STATE.ENRICHED` is set.
2+
// This is loaded to ensure `STATE.ENRICHED` is set.
33
require('mathjax-full/js/a11y/semantic-enrich.js');
4-
const {STATE} = require('mathjax-full/js/core/MathItem.js');
4+
const {newState, STATE} = require('mathjax-full/js/core/MathItem.js');
5+
56

67
//
78
// Remove the data-semantic-* attributes other than data-semantic-speech
@@ -21,16 +22,16 @@ function removeSemanticData(math) {
2122

2223
//
2324
// Moves all speech elements into aria-labels for SVG output. This allows for
24-
// elements without containers some limited exploration.
25+
// elements without containers to have some limited exploration.
2526
//
26-
// Note, that here we cannot walk the source tree, as we alterations are to be
27+
// Note, that here we cannot walk the source tree, as alterations are to be
2728
// done on the typeset element, if it is a SVG node.
2829
//
2930
function speechToRoles(math) {
3031
const root = math.typesetRoot;
3132
const adaptor = math.adaptor;
32-
const svg = adaptor.childNodes(root)[0];
33-
if (!svg || adaptor.kind(svg) !== 'svg') return;
33+
const svg = adaptor.tags(root, 'svg')[0];
34+
if (!svg) return;
3435
adaptor.removeAttribute(svg, 'aria-hidden');
3536
adaptor.removeAttribute(svg, 'role');
3637
const children = [svg];
@@ -85,16 +86,37 @@ exports.sreconfig = function(data) {
8586
Object.assign(MathJax.config.options.sre, config);
8687
};
8788

89+
//
90+
// Let's define some new states for enlisting new renderActions into the queue.
91+
//
92+
// STATE.ENRICHED is the priority of the enrichment. Enrichment happens before
93+
// elements are rendered (i.e., typeset) and therefore all attributes added during
94+
// enrichment will be part of the MathItem.
95+
//
96+
// STATE 1000 is so hight that any other render action should be done by
97+
// then. That is, the MathItem is fully typeset in the document.
98+
//
99+
newState('SIMPLIFY', STATE.ENRICHED + 1);
100+
newState('ROLE', 1000);
101+
newState('DESCRIBE', STATE.ROLE + 1);
88102

89103
//
90-
// The renderActions needed to remove the data-semantic-attributes.
91-
// STATE.ENRICHED is the priority of the enrichment, so this will run just after enrichment.
104+
// The renderActions needed for manipulating MathItems with speech entries.
105+
// We define three render actions, each with two functions:
92106
// The first function is the one for when the document's render() method is called.
93107
// The second is for when a MathItem's render(), rerender() or convert() method is called.
94108
//
109+
// simplify: Removes the data-semantic-attributes except speech directly after enrichment.
110+
//
111+
// role: Adds an aria role to the container element so aria-labels are spoken on custom elements.
112+
// This happens after typesetting.
113+
//
114+
// describe: Rewrites speech attributes into aria-labels with img roles in SVGs.
115+
// This happens after container elements are rewritten.
116+
//
95117
exports.speechAction = {
96118
simplify: [
97-
STATE.ENRICHED + 1,
119+
STATE.SIMPLIFY,
98120
(doc) => {
99121
for (const math of doc.math) {
100122
removeSemanticData(math);
@@ -105,7 +127,7 @@ exports.speechAction = {
105127
}
106128
],
107129
role: [
108-
1000,
130+
STATE.ROLE,
109131
(doc) => {
110132
for (const math of doc.math) {
111133
roleImg(math);
@@ -116,7 +138,7 @@ exports.speechAction = {
116138
}
117139
],
118140
describe: [
119-
1001,
141+
STATE.DESCRIBE,
120142
(doc) => {
121143
for (const math of doc.math) {
122144
speechToRoles(math);

speech/mml2mml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function moveSpeech(math) {
6161
let alttext = '';
6262
math.root.walkTree(node => {
6363
const attributes = node.attributes.getAllAttributes();
64-
console.log(attributes);
6564
if (!alttext && attributes['data-semantic-speech']) {
6665
alttext = attributes['data-semantic-speech'];
6766
}

speech/tex2svg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ MathJax.startup.promise.then(() => {
161161
console.log(adaptor.textContent(MathJax.svgStylesheet()));
162162
} else {
163163
let html = argv.container ? adaptor.outerHTML(node) : adaptor.innerHTML(node);
164-
console.log(argv.styles ? html.replace(/<defs>/, `<defs><style aria-hidden="true">${CSS}</style>`) : html);
164+
console.log(argv.styles ? html.replace(/<defs>/, `<defs><style aria-hidden="true">${CSS}</style>`) : html);
165165
};
166166
});
167167
}).catch(err => console.log(err));

0 commit comments

Comments
 (0)