I need to check the accessibility of HTML code, herewith:
- I need the Node.js API (class of function), not CLI.
- I want to pass the HTML string as parameter, not the URI of file path.
Is should be something like:
import AccessibilityInspector from "package-which_i_need";
AccessibilityInspector.inspect({
rawHTML_Code: `<!doctypehtml><html lang=en><meta charset=utf-8><title>title</title><link href=style.css rel=stylesheet><script src=script.js></script>`,
standard: "WCAG2AAA"
}).
then((issues: Array<AccessibilityInspector.Issue>): void => {
// Log the issues
}).
catch((error: unknown) => {
console.error(error);
})
Below packages does not satisfy to above conditions:
- The pa11y accepts only URI as the first parameter, but not the HTML code.
- According the documentation, the access-sniff accepts only URIs too. Although the raw HTML could be also passed, "Pattern is too long" unclear error could occur. Also, the access-sniff has many vulnerabilities and not being maintained.
Other options?
2
Answers
You can do:
There seems to be a way to do that with
puppeteer
. The gist of it is to render the HTML in a browser and read the page from there, — although the browser is programmatic here.References: