From dc3e4f23d0cced85d3be3dc10a7b034a72d60a56 Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Mon, 1 Jun 2026 09:47:03 +0000 Subject: [PATCH] fixes table splitter extraneous header at bottom on page split bug --- .../authored/RT/layout/paginate_by_element.js | 78 ++++---- document/style_manual.html | 176 +++++++++++++----- 2 files changed, 178 insertions(+), 76 deletions(-) diff --git a/developer/authored/RT/layout/paginate_by_element.js b/developer/authored/RT/layout/paginate_by_element.js index 3e3b894..2955b3b 100644 --- a/developer/authored/RT/layout/paginate_by_element.js +++ b/developer/authored/RT/layout/paginate_by_element.js @@ -136,30 +136,36 @@ window.StyleRT.paginate_by_element = function () { first.appendChild(children[i].cloneNode(true)); } - // Build rest fragment - const rest = el.cloneNode(false); - for (let i = bestCount; i < children.length; i++) { - rest.appendChild(children[i].cloneNode(true)); - } - // Explicitly inject the starting index for ordered lists - if (el.tagName === 'OL') { - const currentStart = parseInt(el.getAttribute('start'), 10) || 1; - rest.setAttribute('start', currentStart + bestCount); - } + // Build rest fragment only if there are remaining items + let rest = null; + if (bestCount < children.length) { + rest = el.cloneNode(false); + for (let i = bestCount; i < children.length; i++) { + rest.appendChild(children[i].cloneNode(true)); + } - // Forward split info - rest._splitInfo = { - type: 'list', - itemHeights: info.itemHeights, - overhead: info.overhead, - offset: start + bestCount - }; + // Explicitly inject the starting index for ordered lists + if (el.tagName === 'OL') { + const currentStart = parseInt(el.getAttribute('start'), 10) || 1; + rest.setAttribute('start', currentStart + bestCount); + } + + // Forward split info + rest._splitInfo = { + type: 'list', + itemHeights: info.itemHeights, + overhead: info.overhead, + offset: start + bestCount + }; + } return { first, rest, firstHeight: bestHeight }; }; } + + function makeTableSplitter(el, info) { const thead = el.querySelector('thead'); const createShell = () => { @@ -205,19 +211,22 @@ window.StyleRT.paginate_by_element = function () { firstBody.appendChild(relevantRows[i].cloneNode(true)); } - const rest = createShell(); - const restBody = rest.querySelector('tbody'); - for (let i = bestCount; i < relevantRows.length; i++) { - restBody.appendChild(relevantRows[i].cloneNode(true)); - } + let rest = null; + if (bestCount < relevantRows.length) { + rest = createShell(); + const restBody = rest.querySelector('tbody'); + for (let i = bestCount; i < relevantRows.length; i++) { + restBody.appendChild(relevantRows[i].cloneNode(true)); + } - rest._splitInfo = { - type: 'table', - rowHeights: info.rowHeights, - overhead: info.overhead, - theadHeight: info.theadHeight, - offset: start + bestCount - }; + rest._splitInfo = { + type: 'table', + rowHeights: info.rowHeights, + overhead: info.overhead, + theadHeight: info.theadHeight, + offset: start + bestCount + }; + } return { first, rest, firstHeight: bestHeight }; }; @@ -256,9 +265,14 @@ window.StyleRT.paginate_by_element = function () { current_batch_seq.push(first); current_h += firstHeight; // exact measured height - // Replace original with remainder - raw_element_seq.splice(i, 1, rest); - // Do not increment i - rest will be processed next + if (rest) { + // Replace original with remainder + raw_element_seq.splice(i, 1, rest); + } else { + // Element is completely consumed + raw_element_seq.splice(i, 1); + } + // Do not increment i - the next element is now at index i } else { // Not even one item fits on this page if (current_batch_seq.length === 0) { diff --git a/document/style_manual.html b/document/style_manual.html index befc746..ebaf512 100644 --- a/document/style_manual.html +++ b/document/style_manual.html @@ -2,7 +2,7 @@ - RT Style System: Reference Manual + The RT semantic HTML tags -

RT Conventions

+

RT conventions

Headings are first letter capitalized. Remaining words are as they would be in English prose.

Exercises

@@ -334,7 +422,7 @@
  • - TOC Generation: What happens if one places an <RT-TOC> tag without a level attribute before the first heading of a section? + TOC Generation: What happens if a person places an <RT-TOC> tag without a level attribute before the first heading of a section?

  • -- 2.20.1