w3c / html-aria

ARIA in HTML
https://w3c.github.io/html-aria/
Other
182 stars 49 forks source link

JSON for implementors #527

Open giacomo-petri opened 2 months ago

giacomo-petri commented 2 months ago

Hi @scottaohara,

while working on implementing the rules, I organized the test cases into a JSON format for easier validation.

I'm not sure if this would be of interest to you, but based on the current structure of the "Implementation Report" page (https://w3c.github.io/html-aria/results/implementation-results.html), here's a vanilla JavaScript snippet that generates the JSON:

var result = {};
var rows = document.querySelectorAll('table:nth-of-type(1) tbody tr');

rows.forEach(function(row) {
    var th = row.querySelector('th');
    if (th) {
        var hrefs = [];
        var td = row.querySelectorAll('td')[2];

        if (td) {
            var links = td.querySelectorAll('a');
            links.forEach(function(link) {
                hrefs.push(link.getAttribute('href'));
            });
        }

        result[th.textContent.trim()] = hrefs;
    }
});

//console.log(result);

I've attached the generated output for your reference. ARIA-in-HTML-json.js.zip

This approach might be similar to the ARIA JSON that implementors use to build the rules (https://github.com/w3c/aria/blob/main/common/script/roleInfo.js).

Let me know if this is useful or if you need something else.

giacomo-petri commented 2 months ago

(Oh, this script is just for the first table titled "Rules of ARIA attribute usage by HTML element.")