4,456
edits
No edit summary |
No edit summary |
||
Line 1,366: | Line 1,366: | ||
// Remove “empty” optional sections so they don’t leave gaps in print. | // Remove “empty” optional sections so they don’t leave gaps in print. | ||
// --- | // --- CLEAN: remove empty paragraphs/whitespace nodes that create phantom gaps | ||
(function () { | |||
// 1) Drop <p> that are visually empty or only /whitespace | |||
var ps = doc.querySelectorAll("#article-content p"); | |||
Array.prototype.forEach.call(ps, function (p) { | |||
var txt = (p.textContent || "").replace(/\u00a0/g, " ").trim(); | |||
// also ignore spans that were left with only <br> | |||
var onlyBr = | |||
p.children.length === 1 && p.firstElementChild.tagName === "BR"; | |||
if ( | |||
(!txt && | |||
!p.querySelector("img, a, strong, em, span:not(:empty)")) || | |||
onlyBr | |||
) { | |||
p.parentNode && p.parentNode.removeChild(p); | |||
} | |||
}); | |||
// 2) Remove pure-whitespace text nodes directly under #article-content | |||
var root = doc.getElementById("article-content"); | |||
if (root) { | |||
Array.prototype.slice.call(root.childNodes).forEach(function (n) { | |||
if (n.nodeType === 3 && !n.textContent.replace(/\s+/g, "")) { | |||
root.removeChild(n); | |||
} | |||
}); | |||
} | |||
})(); | |||
(function () { | (function () { | ||
var css = | var css = | ||
"@media print{" + | "@media print{" + | ||
/ | // Paragraphs inside rich text: no big UA margins, tiny rhythm | ||
" .article-description p,.article-reflection p,.article-external-reference p,.article-quote p{margin:0 0 1.2mm!important;}" + | |||
" .article-description p:last-child,.article-reflection p:last-child,.article-external-reference p:last-child,.article-quote p:last-child{margin-bottom:0!important;}" + | |||
" .article-description p,.article-reflection p,.article-external-reference p,.article-quote p{margin:0!important;}" + | // Ruled sections: keep only tiny space for the hairline | ||
" .article-description p | " .article-entry-number,.link-pdf,.article-type,.article-metadata,.article-images,.article-description,.article-reflection,.article-external-reference,.article-quote,.article-mod-line{" + | ||
/ | " padding-bottom:1mm!important;" + | ||
" .article-entry-number, | |||
" padding-bottom: | |||
" }" + | " }" + | ||
/ | // Labels: reset default top margin, then add ONE small spacer when following any ruled block | ||
" .article-label-description, | " .article-label-description,.article-label-reflection,.article-label-external-reference,.article-label-quote,.article-label-modification-date{margin-top:0!important;}" + | ||
" .article-entry-number + .article-label-description," + | " .article-entry-number + .article-label-description," + | ||
" .link-pdf + .article-label-description," + | " .link-pdf + .article-label-description," + | ||
Line 1,406: | Line 1,416: | ||
" .article-external-reference + .article-label-quote," + | " .article-external-reference + .article-label-quote," + | ||
" .article-quote + .article-label-modification-date{" + | " .article-quote + .article-label-modification-date{" + | ||
" margin-top: | " margin-top:0.9mm!important;" /* tweak this ONE value to taste */ + | ||
" }" + | " }" + | ||
/ | // No gap between a label and its own body | ||
" .article-label-description + .article-description," + | " .article-label-description + .article-description," + | ||
" .article-label-reflection + .article-reflection," + | " .article-label-reflection + .article-reflection," + | ||
" .article-label-external-reference + .article-external-reference," + | " .article-label-external-reference + .article-external-reference," + | ||
" .article-label-quote + .article-quote," + | " .article-label-quote + .article-quote," + | ||
" .article-label-modification-date + .article-modification-date{" + | " .article-label-modification-date + .article-modification-date{margin-top:0!important;}" + | ||
" | // Metadata grid: avoid bottom gap | ||
" }" + | " .article-metadata{margin-bottom:0!important;}" + | ||
// Title/link row: avoid extra gap from inner elements | |||
" .article-title-link{margin:0!important;padding:0!important;}" + | |||
" .article-title-link > *{margin:0!important;}" + | |||
" .link-pdf{margin-top:0!important;}" + | |||
// Final block: no trailing hairline | |||
" #article-content > :last-child{padding-bottom:0!important;}" + | " #article-content > :last-child{padding-bottom:0!important;}" + | ||
" #article-content > :last-child::after{content:none!important;}" + | " #article-content > :last-child::after{content:none!important;}" + |