Skip to content

Commit

Permalink
feat(script) Fix aria issues in the generated HTML #10.
Browse files Browse the repository at this point in the history
  • Loading branch information
skounis committed Feb 10, 2023
1 parent d4ec068 commit ec637f1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fs = require("fs");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;

let idDict = {};

const inputFilePath = "arf.html";
const outputFilePath = "output.html";

fs.readFile(inputFilePath, "utf-8", (err, html) => {
if (err) {
console.error(err);
return;
}

const dom = new JSDOM(html);
const document = dom.window.document;

// Fix duplicate ids
document.querySelectorAll("[id]").forEach(element => {
let id = element.getAttribute("id");
if (idDict[id]) {
let newId = id + "_" + Math.floor(Math.random() * 100000);
element.setAttribute("id", newId);
idDict[newId] = true;
} else {
idDict[id] = true;
}
});

// Remove the `role='doc-endnote'` from the `li` elements
document.querySelectorAll("li[role='doc-endnote']").forEach(element => {
element.removeAttribute("role");
});

fs.writeFile(outputFilePath, dom.serialize(), err => {
if (err) {
console.error(err);
return;
}

console.log(`Output written to ${outputFilePath}`);
});
});

0 comments on commit ec637f1

Please sign in to comment.