-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(script) Fix aria issues in the generated HTML #10.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); | ||
}); |