Honor expandChorusDirective in PdfFormatter - #2271
Conversation
2bfb382 to
b56b75c
Compare
The PDF layout engine always read the song's bodyParagraphs, so
{chorus} directives were never expanded in PDF output, unlike the
text and HTML formatters. The engine now resolves the paragraphs to
lay out from the config (expanding {chorus} when enabled) and returns
them, instead of writing them back onto the song.
Song#renderParagraphs is no longer used internally and is deprecated.
b56b75c to
1d3c38d
Compare
| .configure({ | ||
| layout: { sections: { base: { display: { repeatedSections: 'full' } } } }, | ||
| expandChorusDirective, | ||
| }) |
There was a problem hiding this comment.
Noticing the fact that repeatedSections needs to be set to full for this to work. So I dug around on that.
- expandChorusDirective recalls the chorus.
- repeatedSections then processes the recalled section.
- PDF defaults repeatedSections to title_only.
As a result, {chorus} is expanded, but the default PDF configuration can remove its lyrics and retain only its label. hide can remove the recalled section. full retains the full section.
Labels also affect the result. A bare {chorus} can match the original chorus label and be reduced as a repeat. {chorus: Sing it} can use a different label and avoid that match. The same configuration can therefore produce different output based on the directive label.
I see three possible paths:
- Keep the current processing order. Treat repeatedSections as the final display rule. Add a warning and document the interaction.
- Make expandChorusDirective: true always render the full recalled chorus. This requires cloned lines and source tracking so repeat processing can skip generated sections.
- Add a separate chorus-directive display option. This is a larger configuration and migration change.
I prefer path 1 for this PR because it keeps the fix small. I suggest these amendments:
-
Pass expandChorusDirective through MeasuredHtmlFormatter as well. It uses the same layout engine.
-
Use the shared warn() helper when expandChorusDirective is true and repeatedSections is not full.
-
Use wording such as:
│ expandChorusDirective runs before repeatedSections. The current repeated-section mode can hide part or all of the recalled chorus. Use repeatedSections:
│ "full" to show the full chorus.
Warn only in this case:
expandChorusDirective === true &&
repeatedSections !== 'full'This would make the current behavior explicit without expanding this bug fix into a larger API redesign, since we kinda have overlapping responsibility in the config with repeatedSections and expandChorusDirective
Fixes #2240
The PDF layout engine always read the song's
bodyParagraphs, so{chorus}directives were never expanded in PDF output — unlikeTextFormatterandHtmlFormatter, which honorexpandChorusDirective.Changes
LayoutEnginenow resolves the paragraphs to lay out from the config: it usesexpandedBodyParagraphswhenexpandChorusDirectiveis enabled, and returns the resolved array instead of writing it back onto the song.expandChorusDirectiveis added toLayoutConfigand passed through fromPdfFormatter.song.clone()in paragraph selection: the source paragraphs are never mutated (all pushed paragraphs are clones), and cloning stripped line numbers, whichLineExpanderneeds to expand{chorus}.Song#renderParagraphsis no longer used internally and is deprecated.Note on
repeatedSectionsThe PDF default
repeatedSections: 'title_only'collapses repeated sections to their title. Since an expanded{chorus}reproduces the chorus, it is treated as a repeat and collapsed to its title under the default config. To get output identical to text/HTML (the expanded chorus rendered in full), combineexpandChorusDirective: truewith a non-collapsingrepeatedSectionssuch as'full'.Tests
Added PDF formatter tests asserting chorus lyrics are laid out twice when
expandChorusDirective: trueand once whenfalse(withrepeatedSections: 'full').