Files
django-anymail/docs/_static/table-formatting.js
Mike Edmunds 53546ffc19 Docs: simplify editing ESP feature matrix
Move the big ESP feature matrix table
into a CSV file for easier maintenance.

Remove the doc8 line-length exception
the old table needed.

Docutils csv-table directive doesn't
support colspan on the subheadings
like the old table did. Add some JS
that replicates the old behavior.
(The new table is still readable even
with JS disabled.)
2024-02-19 15:00:43 -08:00

41 lines
1.0 KiB
JavaScript

/**
* Return the first sibling of el that matches CSS selector, or null if no matches.
* @param {HTMLElement} el
* @param {string} selector
* @returns {HTMLElement|null}
*/
function nextSiblingMatching(el, selector) {
while (el && el.nextElementSibling) {
el = el.nextElementSibling;
if (el.matches(selector)) {
return el;
}
}
return null;
}
/**
* Convert runs of empty <td> elements to a colspan on the first <td>.
*/
function collapseEmptyTableCells() {
document.querySelectorAll(".rst-content tr:has(td:empty)").forEach((tr) => {
for (
let spanStart = tr.querySelector("td");
spanStart;
spanStart = nextSiblingMatching(spanStart, "td")
) {
let emptyCell;
while ((emptyCell = nextSiblingMatching(spanStart, "td:empty"))) {
emptyCell.remove();
spanStart.colSpan++;
}
}
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", collapseEmptyTableCells);
} else {
collapseEmptyTableCells();
}