From: Thomas Walker Lynch Date: Wed, 1 Jul 2026 10:27:08 +0000 (+0000) Subject: fixes penchant to orphan headings .. looking good X-Git-Url: https://git.reasoningtechnology.com/RT-Manuscript_locator.js?a=commitdiff_plain;h=e9dcac57fede6530b2ab74d02690cb04aa630e49;p=RT-Style fixes penchant to orphan headings .. looking good --- diff --git a/developer/authored/Manuscript.copy/Document/manual.html b/developer/authored/Manuscript.copy/Document/manual.html index d5ff9f2..d9bbc77 100644 --- a/developer/authored/Manuscript.copy/Document/manual.html +++ b/developer/authored/Manuscript.copy/Document/manual.html @@ -44,7 +44,7 @@

-

Manuscript Types

+

Manuscript types

These are the current top level semantic tag environments. They affect the formatting of scoped content. This includes the custom semantic tags, and can also include standard HTML tags.

@@ -72,7 +72,7 @@ -

Article Manuscript

+

Article manuscript

Here is an example header for an article

@@ -131,7 +131,7 @@ -

Layout Environments

+

Layout environments

This can be written inline with text, or as blocks.

@@ -262,6 +262,42 @@ +

Cross reference

+

+ The Note tags provide a two pass mechanism for cross referencing content and page numbers throughout the document. +

+ + + + + + + + + + + + + + + + + +
TagDescription & Arguments
<RT·Note·write> + Records the scoped content and its resolved page number into the reference dictionary.
+
+ Attributes:
+ key: Required unique identifier for the note. +
+
<RT·Note·read> + Retrieves data from a previously recorded note and injects it as innerHTML.
+
+ Attributes:
+ key: Required identifier matching a write tag.
+ field: Selects the data to retrieve. Valid options are "content" (the original scoped HTML) or "page" (the computed page number). (Default: "content") +
+
+

Annotation

@@ -316,7 +352,7 @@ The <RT·book> container is reserved for multi chapter compilations. It introduces tags designed exclusively for macro level document orchestration. (Does not currently exist, rather using the Article Tech Ref format.)

-

Book Specific Tags

+

Book specific tags

@@ -332,7 +368,7 @@
-

Global Widgets

+

Global widgets

diff --git a/developer/authored/Manuscript.copy/Layout/paginate.js b/developer/authored/Manuscript.copy/Layout/paginate.js index bff6dce..e9d8060 100644 --- a/developer/authored/Manuscript.copy/Layout/paginate.js +++ b/developer/authored/Manuscript.copy/Layout/paginate.js @@ -220,7 +220,7 @@ // ========================================================= // PAGINATE 0: CHUNKING & INJECTING STRUCTURE // ========================================================= - paginate_0 = function(){ + function paginate_0(){ if(debug.log) debug.log('paginate_0' ,'Running initial document chunking'); const article_seq = document.querySelectorAll('RT·article'); @@ -257,7 +257,7 @@ function paginateArticle(article){ const raw_element_seq = Array.from(article.children).filter(el => - !['SCRIPT' ,'STYLE' ,'RT·PAGE'].includes(el.tagName) + !['SCRIPT' ,'STYLE' ,'RT·PAGE'].includes((el.tagName || '').toUpperCase()) ); if(raw_element_seq.length === 0) return; @@ -294,10 +294,37 @@ current_batch_seq.push(frame); i++; } else { - page_seq.push(current_batch_seq); - current_batch_seq = []; - current_h = 0; - raw_element_seq[i] = rest || el; + // Element is split but first chunk fails to fit. Evict any stranded headings. + let backtrack_seq = []; + let backtrack_h = 0; + + while(current_batch_seq.length > 0){ + const last = current_batch_seq[current_batch_seq.length - 1]; + if(!/^H[1-6]$/i.test(last.tagName)) break; + const popped = current_batch_seq.pop(); + backtrack_seq.unshift(popped); + backtrack_h += getElHeight(popped); + } + + if(current_batch_seq.length > 0){ + page_seq.push(current_batch_seq); + current_batch_seq = backtrack_seq; + current_h = backtrack_h; + // Leave 'i' alone to re-evaluate 'el' against the fresh page sequence + } else { + // If only headings existed, accept the massive frame inline to avoid loops + const frame = document.createElement('RT·scroll-frame'); + frame.style.display = 'block'; + frame.style.overflowY = 'auto'; + frame.style.maxHeight = page_height_limit + 'px'; + frame.appendChild(el); + + current_batch_seq = backtrack_seq; + current_h = backtrack_h; + + current_batch_seq.push(frame); + i++; + } } } continue; @@ -306,13 +333,25 @@ const h = getElHeight(el); const is_RT_page_break = el.tagName && el.tagName.toLowerCase() === 'rt·page-break'; - if( (is_RT_page_break || current_h + h > page_height_limit) && current_batch_seq.length > 0 ){ + // Explicit Page Break Logic - Execute immediately without backward traversal + if(is_RT_page_break){ + if(current_batch_seq.length > 0){ + page_seq.push(current_batch_seq); + current_batch_seq = []; + current_h = 0; + } + i++; + continue; + } + + // Standard Dimension Overflow Logic - Check for orphaned headers + if( current_h + h > page_height_limit && current_batch_seq.length > 0 ){ let backtrack_seq = []; let backtrack_h = 0; while(current_batch_seq.length > 0){ const last = current_batch_seq[current_batch_seq.length - 1]; - if(!/^H[1-6]/.test(last.tagName)) break; + if(!/^H[1-6]$/i.test(last.tagName)) break; const popped = current_batch_seq.pop(); backtrack_seq.unshift(popped); backtrack_h += getElHeight(popped); @@ -323,9 +362,9 @@ current_batch_seq = backtrack_seq; current_h = backtrack_h; } else { - page_seq.push(backtrack_seq); - current_batch_seq = []; - current_h = 0; + // Document structure resolved entirely to sequential headings that breached bounds. + current_batch_seq = backtrack_seq; + current_h = backtrack_h; } } @@ -424,12 +463,12 @@ measureContainer.remove(); measureContainer = null; } - }; + } // ========================================================= // PAGINATE 1: ABSORB DIMENSIONAL DELTA // ========================================================= - paginate_1 = function(){ + function paginate_1(){ if(debug.log) debug.log('paginate_1' ,'Adjusting final page heights after component injections'); const rendered_pages = document.querySelectorAll('RT·page'); @@ -439,7 +478,7 @@ page.style.minHeight = actual_height + 'px'; } }); - }; + } //---------------------------------------- // Registration upon load