Skip to content

Commit 35a85c5

Browse files
committed
fix(renderer-css): give each section its own grid in print for break-inside: avoid
Sections had an inline style="display: contents" which made break-inside: avoid via ::part() ineffective — inline styles outrank external ::part() rules, so the constraint was silently ignored. Remove the redundant inline style (the CSS already sets display:contents). Add a @media print block that promotes song-grid to display:block and each section to its own CSS grid (using the same inherited --beat-cols / --min-beat-width variables), with break-inside: avoid. Rows continue to use subgrid, now referencing the section grid rather than song-grid.
1 parent e2aad28 commit 35a85c5

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

packages/grigson/src/renderers/html.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,9 @@ describe('HtmlRenderer', () => {
626626
});
627627

628628
describe('section structure', () => {
629-
it('section element has part="section" and display:contents style', () => {
629+
it('section element has part="section"', () => {
630630
const html = renderer.render(parseSong('[Verse]\n| C |\n'));
631631
expect(html).toContain('part="section"');
632-
expect(html).toContain('display: contents');
633632
});
634633

635634
it('section label is rendered inside section element', () => {

packages/grigson/src/renderers/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ export class HtmlRenderer implements GrigsonRenderer {
729729
html += `<div part="song-grid">`;
730730

731731
for (const section of source.sections) {
732-
html += `<section part="section" style="display: contents">`;
732+
html += `<section part="section">`;
733733

734734
if (section.label !== null) {
735735
html += `<h2 part="section-label">${section.label}</h2>`;

packages/grigson/src/renderers/renderer-css.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,22 @@ export function getRendererStyles(typeface: string = 'sans'): string {
350350
font-size: var(--grigson-simile-font-size);
351351
transform: translateY(var(--grigson-simile-offset));
352352
}
353+
354+
/* ── Print: give each section its own grid so break-inside: avoid works ── */
355+
@media print {
356+
[part="song-grid"] {
357+
display: block;
358+
}
359+
[part="section"] {
360+
display: grid;
361+
grid-template-columns: auto repeat(var(--beat-cols), minmax(var(--min-beat-width), 1fr) auto);
362+
row-gap: var(--grigson-row-gap);
363+
break-inside: avoid;
364+
margin-bottom: var(--grigson-section-gap);
365+
}
366+
[part="section-label"] {
367+
margin-top: 0;
368+
}
369+
}
353370
`;
354371
}

0 commit comments

Comments
 (0)