git » alan.git » commit 400688b

Adjust section breaks to keep heading with content

author Alan Dipert
2025-12-04 05:13:06 UTC
committer Alan Dipert
2025-12-04 05:13:06 UTC
parent 74044a031f142e2133403da67980291f733d2c85

Adjust section breaks to keep heading with content

render_text.py +3 -1

diff --git a/render_text.py b/render_text.py
index e5f5954..6a362e7 100644
--- a/render_text.py
+++ b/render_text.py
@@ -46,7 +46,9 @@ def render_booklet(data: Dict[str, Any]) -> str:
 
     for sec_idx, section in enumerate(data.get("sections", [])):
         lines.append("<div style=\"page-break-after: always;\"></div>")
-        lines.append(f"<h2 style=\"page-break-after: always;\">Section {sec_idx + 1}</h2>")
+        # start each section after a break, but keep the heading with content
+        lines.append("<div style=\"page-break-before: always;\"></div>")
+        lines.append(f"<h2 style=\"page-break-after: avoid;\">Section {sec_idx + 1}</h2>")
         for intro in section.get("intro_text", []):
             lines.append(intro)
             lines.append("")