mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 07:24:56 -10:00
* Lint the website with the frontend's ESLint config instead of a diverging copy, selecting elements by data attributes * Give the crate graph's marker attribute a value, cache npm in the website workflow, and mention installing the website's packages
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
window.addEventListener("DOMContentLoaded", () => {
|
|
// eslint-disable-next-line graphite/require-data-selectors -- Markdown writes these paragraphs, which leaves no way to mark them
|
|
document.querySelectorAll("section p").forEach((paragraph) => {
|
|
const /** @type {[Text, NodeList][]} */ mutationQueue = [];
|
|
|
|
// Recursively traverse the DOM tree and modify the text nodes
|
|
const recursivelyAddWbr = (/** @type {ChildNode} **/ node) => {
|
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
if (!(node instanceof Text)) return;
|
|
|
|
const newNodes = node.textContent.split("/");
|
|
for (let i = 0; i < newNodes.length - 1; i++) {
|
|
newNodes[i] += "/";
|
|
}
|
|
|
|
const tempSpan = document.createElement("span");
|
|
tempSpan.innerHTML = newNodes.join("<wbr>");
|
|
const replacementNodes = tempSpan.childNodes;
|
|
|
|
mutationQueue.push([node, replacementNodes]);
|
|
} else {
|
|
node.childNodes.forEach(recursivelyAddWbr);
|
|
}
|
|
};
|
|
|
|
// Perform the recursive traversal
|
|
recursivelyAddWbr(paragraph);
|
|
|
|
// Replace the text nodes
|
|
mutationQueue.forEach(([node, newNodes]) => node.replaceWith(...newNodes));
|
|
});
|
|
});
|