-
Notifications
You must be signed in to change notification settings - Fork 191
fix(layout): suppress pageBreakBefore directly after explicit break (SD-3366) #3712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
tupizz
wants to merge
3
commits into
main
from
tadeu/sd-3366-bug-pagebreakbefore-inside-style-preceded-by-pagebreak
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...ditor/src/editors/v1/core/layout-adapter/converters/paragraph.page-break-emission.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /** | ||
| * Pins the FlowBlock emission contract around explicit page breaks (SD-3366). | ||
| * | ||
| * The layout engine suppresses a style/direct pageBreakBefore when it directly | ||
| * follows an explicit page break, identified structurally as the window | ||
| * [explicit pageBreak, empty remnant paragraph, pageBreak source=pageBreakBefore] | ||
| * (see isPageBreakBeforeSatisfiedByExplicitBreak in @superdoc/layout-engine). | ||
| * That check relies on the emission shapes asserted here. If one of these | ||
| * tests fails after an adapter change, the layout-engine window check must be | ||
| * revisited together with it. | ||
| */ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { toFlowBlocks as baseToFlowBlocks } from '../index.js'; | ||
| import type { PMNode, AdapterOptions } from '../index.js'; | ||
|
|
||
| const DEFAULT_CONVERTER_CONTEXT = { | ||
| docx: {}, | ||
| translatedLinkedStyles: { docDefaults: {}, latentStyles: {}, styles: {} }, | ||
| translatedNumbering: { abstracts: {}, definitions: {} }, | ||
| }; | ||
|
|
||
| const toFlowBlocks = (content: object[], options: AdapterOptions = {}) => | ||
| baseToFlowBlocks({ type: 'doc', content } as unknown as PMNode, { | ||
| converterContext: DEFAULT_CONVERTER_CONTEXT, | ||
| ...options, | ||
| }); | ||
|
|
||
| const textPara = (text: string) => ({ | ||
| type: 'paragraph', | ||
| attrs: { paragraphProperties: {} }, | ||
| content: [{ type: 'run', attrs: {}, content: [{ type: 'text', text }] }], | ||
| }); | ||
|
|
||
| /** Paragraph whose only content is an explicit page break (`w:br w:type="page"`). */ | ||
| const breakPara = () => ({ | ||
| type: 'paragraph', | ||
| attrs: { paragraphProperties: {} }, | ||
| content: [{ type: 'run', attrs: {}, content: [{ type: 'hardBreak', attrs: { lineBreakType: 'page' } }] }], | ||
| }); | ||
|
|
||
| const pbbPara = (text: string) => ({ | ||
| type: 'paragraph', | ||
| attrs: { paragraphProperties: { pageBreakBefore: true } }, | ||
| content: [{ type: 'run', attrs: {}, content: [{ type: 'text', text }] }], | ||
| }); | ||
|
|
||
| type EmittedShape = { kind: string; source?: unknown; texts?: Array<string | undefined> }; | ||
|
|
||
| const shapeOf = (blocks: ReturnType<typeof toFlowBlocks>['blocks']): EmittedShape[] => | ||
| blocks.map((block) => { | ||
| const b = block as { kind: string; attrs?: Record<string, unknown>; runs?: Array<{ text?: string }> }; | ||
| const shape: EmittedShape = { kind: b.kind }; | ||
| if (b.attrs?.source !== undefined) shape.source = b.attrs.source; | ||
| if (b.runs) shape.texts = b.runs.map((r) => r.text); | ||
| return shape; | ||
| }); | ||
|
|
||
| describe('explicit page break emission shapes (SD-3366)', () => { | ||
| it('a break-only paragraph emits the pageBreak followed by its empty remnant paragraph', () => { | ||
| const { blocks } = toFlowBlocks([textPara('Prior'), breakPara(), pbbPara('Styled')]); | ||
|
|
||
| expect(shapeOf(blocks)).toEqual([ | ||
| { kind: 'paragraph', texts: ['Prior'] }, | ||
| { kind: 'pageBreak' }, | ||
| { kind: 'paragraph', texts: [''] }, | ||
| { kind: 'pageBreak', source: 'pageBreakBefore' }, | ||
| { kind: 'paragraph', texts: ['Styled'] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('a break at the end of a text paragraph emits no remnant paragraph', () => { | ||
| const { blocks } = toFlowBlocks([ | ||
| { | ||
| type: 'paragraph', | ||
| attrs: { paragraphProperties: {} }, | ||
| content: [ | ||
| { | ||
| type: 'run', | ||
| attrs: {}, | ||
| content: [ | ||
| { type: 'text', text: 'Prior' }, | ||
| { type: 'hardBreak', attrs: { lineBreakType: 'page' } }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| pbbPara('Styled'), | ||
| ]); | ||
|
|
||
| expect(shapeOf(blocks)).toEqual([ | ||
| { kind: 'paragraph', texts: ['Prior'] }, | ||
| { kind: 'pageBreak' }, | ||
| { kind: 'pageBreak', source: 'pageBreakBefore' }, | ||
| { kind: 'paragraph', texts: ['Styled'] }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('text after the break in the same paragraph emits a non-empty trailing paragraph', () => { | ||
| const { blocks } = toFlowBlocks([ | ||
| { | ||
| type: 'paragraph', | ||
| attrs: { paragraphProperties: {} }, | ||
| content: [ | ||
| { | ||
| type: 'run', | ||
| attrs: {}, | ||
| content: [ | ||
| { type: 'hardBreak', attrs: { lineBreakType: 'page' } }, | ||
| { type: 'text', text: 'After' }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| pbbPara('Styled'), | ||
| ]); | ||
|
|
||
| expect(shapeOf(blocks)).toEqual([ | ||
| { kind: 'pageBreak' }, | ||
| { kind: 'paragraph', texts: ['After'] }, | ||
| { kind: 'pageBreak', source: 'pageBreakBefore' }, | ||
| { kind: 'paragraph', texts: ['Styled'] }, | ||
| ]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.