testaro 60.10.2 → 60.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/testaro/captionLoc.js +33 -14
package/package.json
CHANGED
package/testaro/captionLoc.js
CHANGED
|
@@ -28,21 +28,40 @@
|
|
|
28
28
|
Report caption elements that are not the first child of their table element.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// FUNCTIONS
|
|
32
32
|
|
|
33
33
|
exports.reporter = async (page, withItems) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
// Return totals and standard instances for the rule.
|
|
35
|
+
return await page.evaluate(withItems => {
|
|
36
|
+
// Get all candidates, i.e. caption elements.
|
|
37
|
+
const candidates = document.body.querySelectorAll('caption');
|
|
38
|
+
let violationCount = 0;
|
|
39
|
+
const instances = [];
|
|
40
|
+
// For each candidate:
|
|
41
|
+
candidates.forEach(element => {
|
|
42
|
+
const parent = element.parentElement;
|
|
43
|
+
// If the element is not the first child of a table element:
|
|
44
|
+
if (! parent || parent.tagName !== 'TABLE' || parent.firstElementChild !== el) {
|
|
45
|
+
// Increment the violation count.
|
|
46
|
+
violationCount++;
|
|
47
|
+
// If itemization is required:
|
|
48
|
+
if (withItems) {
|
|
49
|
+
const what = 'caption element is not the first child of a table element';
|
|
50
|
+
// Add an instance to the instances.
|
|
51
|
+
instances.push(window.getInstance(element, 'captionLoc', what, 1, 3));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
40
54
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
// If there are any violations and itemization is not required:
|
|
56
|
+
if (violationCount && ! withItems) {
|
|
57
|
+
const what = 'caption elements are not the first children of table elements';
|
|
58
|
+
// Add a summary instance to the instances.
|
|
59
|
+
instances.push(window.getInstance(null, 'captionLoc', what, violationCount, 3, 'caption'));
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
data: {},
|
|
63
|
+
totals: [0, 0, 0, violationCount],
|
|
64
|
+
standardInstances: instances
|
|
65
|
+
}
|
|
66
|
+
}, withItems);
|
|
48
67
|
};
|