From ec637f1342c4ed68ebb97809374353c86ec588a4 Mon Sep 17 00:00:00 2001 From: Stavros Kounis Date: Fri, 10 Feb 2023 13:48:01 +0100 Subject: [PATCH] feat(script) Fix aria issues in the generated HTML #10. --- fix.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 fix.js diff --git a/fix.js b/fix.js new file mode 100644 index 0000000..a52ef40 --- /dev/null +++ b/fix.js @@ -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}`); + }); +});