mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
fix table's borders
This commit is contained in:
@@ -218,6 +218,14 @@ function isEffectivelyEmptyBlock(node) {
|
|||||||
return meaningfulChildren.length === 0;
|
return meaningfulChildren.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasExplicitBorderStyle(node) {
|
||||||
|
if (!node || typeof node.getAttribute !== "function") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const style = String(node.getAttribute("style") || "");
|
||||||
|
return /(^|;)\s*border(?:-(top|right|bottom|left))?\s*:/i.test(style);
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeTableSpacing(html) {
|
function normalizeTableSpacing(html) {
|
||||||
const dom = new JSDOM(`<div id="root">${String(html || "")}</div>`);
|
const dom = new JSDOM(`<div id="root">${String(html || "")}</div>`);
|
||||||
const { document } = dom.window;
|
const { document } = dom.window;
|
||||||
@@ -226,6 +234,14 @@ function normalizeTableSpacing(html) {
|
|||||||
return String(html || "");
|
return String(html || "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep user-intended border styles, but remove implicit border attributes
|
||||||
|
// (for example border="1") when no explicit CSS border was set.
|
||||||
|
root.querySelectorAll("table, td, th").forEach((node) => {
|
||||||
|
if (node.hasAttribute("border") && !hasExplicitBorderStyle(node)) {
|
||||||
|
node.removeAttribute("border");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const tables = root.querySelectorAll("table");
|
const tables = root.querySelectorAll("table");
|
||||||
tables.forEach((table) => {
|
tables.forEach((table) => {
|
||||||
let prev = table.previousElementSibling;
|
let prev = table.previousElementSibling;
|
||||||
|
|||||||
+10
-10
@@ -617,20 +617,20 @@ label {
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep published editor tables borderless unless explicitly restyled by page-specific CSS. */
|
/* Default to borderless tables, but keep any explicit per-cell/table border styling. */
|
||||||
.rendered-html table,
|
|
||||||
.rendered-html table tbody,
|
|
||||||
.rendered-html table thead,
|
|
||||||
.rendered-html table tr,
|
|
||||||
.rendered-html table td,
|
|
||||||
.rendered-html table th {
|
|
||||||
border: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.rendered-html table {
|
.rendered-html table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rendered-html table:not([style*="border"]) {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rendered-html table td:not([style*="border"]),
|
||||||
|
.rendered-html table th:not([style*="border"]) {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
.rendered-html {
|
.rendered-html {
|
||||||
display: flow-root;
|
display: flow-root;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user