Skip to content

Commit a0ed179

Browse files
fix(layout): trim dead section token branch
1 parent 9622750 commit a0ed179

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

packages/layout-engine/layout-bridge/test/resolveHeaderFooterTokens.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,35 @@ describe('resolveHeaderFooterTokens', () => {
114114
expect((block.runs[1] as TextRun).token).toBe('totalPageCount');
115115
});
116116

117+
it('should resolve formatted sectionPageCount token from section context', () => {
118+
const blocks: FlowBlock[] = [
119+
{
120+
kind: 'paragraph',
121+
id: 'footer-section-pages',
122+
runs: [
123+
{
124+
text: 'Section pages: ',
125+
fontFamily: 'Arial',
126+
fontSize: 12,
127+
},
128+
{
129+
text: '0',
130+
token: 'sectionPageCount',
131+
pageNumberFormat: 'upperRoman',
132+
fontFamily: 'Arial',
133+
fontSize: 12,
134+
} as TextRun,
135+
],
136+
} as ParagraphBlock,
137+
];
138+
139+
resolveHeaderFooterTokens(blocks, 1, 99, '1', 1, 4);
140+
141+
const block = blocks[0] as ParagraphBlock;
142+
expect(block.runs[1].text).toBe('IV');
143+
expect((block.runs[1] as TextRun).token).toBe('sectionPageCount');
144+
});
145+
117146
it('should resolve both tokens in the same block', () => {
118147
const blocks: FlowBlock[] = [
119148
{

packages/layout-engine/layout-engine/src/resolvePageTokens.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,7 @@ function cloneBlockWithResolvedTokens(
268268
* }
269269
* ```
270270
*/
271-
export function resolveTokensInBlock(
272-
block: ParagraphBlock,
273-
pageNumber: number,
274-
totalPages: number,
275-
sectionPageCount: number = totalPages,
276-
): boolean {
271+
export function resolveTokensInBlock(block: ParagraphBlock, pageNumber: number, totalPages: number): boolean {
277272
if (block.kind !== 'paragraph') {
278273
return false;
279274
}
@@ -291,7 +286,6 @@ export function resolveTokensInBlock(
291286

292287
const pageNumberStr = String(pageNumber);
293288
const totalPagesStr = String(totalPages);
294-
const sectionPageCountStr = String(sectionPageCount);
295289
let blockModified = false;
296290

297291
// Iterate through runs in the paragraph
@@ -311,13 +305,6 @@ export function resolveTokensInBlock(
311305
// Clear token metadata to treat as normal text after resolution
312306
delete run.token;
313307
blockModified = true;
314-
} else if (run.token === 'sectionPageCount') {
315-
run.text = run.pageNumberFormat
316-
? formatPageNumber(sectionPageCount, run.pageNumberFormat)
317-
: sectionPageCountStr;
318-
delete run.token;
319-
delete run.pageNumberFormat;
320-
blockModified = true;
321308
}
322309
// Note: pageReference tokens are handled by resolvePageRefs.ts
323310
}

0 commit comments

Comments
 (0)