-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into u/julairoldi/investigate-image
- Loading branch information
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
17 changes: 17 additions & 0 deletions
17
packages/roosterjs-content-model-core/lib/override/pasteWhiteSpaceFormatParser.ts
This file contains 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,17 @@ | ||
import type { FormatParser, WhiteSpaceFormat } from 'roosterjs-content-model-types'; | ||
|
||
const WhiteSpacePre = 'pre'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const pasteWhiteSpaceFormatParser: FormatParser<WhiteSpaceFormat> = ( | ||
format, | ||
element, | ||
context, | ||
defaultStyle | ||
) => { | ||
if (element.style.whiteSpace != WhiteSpacePre) { | ||
context.defaultFormatParsers.whiteSpace?.(format, element, context, defaultStyle); | ||
} | ||
}; |
This file contains 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
39 changes: 39 additions & 0 deletions
39
packages/roosterjs-content-model-core/test/overrides/pasteWhiteSpaceFormatParserTest.ts
This file contains 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,39 @@ | ||
import { pasteWhiteSpaceFormatParser } from '../../lib/override/pasteWhiteSpaceFormatParser'; | ||
import { WhiteSpaceFormat } from 'roosterjs-content-model-types/lib'; | ||
|
||
describe('pasteWhiteSpaceFormatParser', () => { | ||
let format: WhiteSpaceFormat; | ||
let element: HTMLElement; | ||
let context: any; | ||
let defaultStyle: any; | ||
let defaultParserSpy: jasmine.Spy; | ||
|
||
beforeEach(() => { | ||
format = {}; | ||
element = document.createElement('div'); | ||
defaultParserSpy = jasmine.createSpy(); | ||
context = { | ||
defaultFormatParsers: { | ||
whiteSpace: defaultParserSpy, | ||
}, | ||
}; | ||
defaultStyle = {}; | ||
}); | ||
|
||
it('should call default whiteSpace parser when element.style.whiteSpace is not "pre"', () => { | ||
element.style.whiteSpace = 'normal'; | ||
pasteWhiteSpaceFormatParser(format, element, context, defaultStyle); | ||
expect(context.defaultFormatParsers.whiteSpace).toHaveBeenCalledWith( | ||
format, | ||
element, | ||
context, | ||
defaultStyle | ||
); | ||
}); | ||
|
||
it('should not call default whiteSpace parser when element.style.whiteSpace is "pre"', () => { | ||
element.style.whiteSpace = 'pre'; | ||
pasteWhiteSpaceFormatParser(format, element, context, defaultStyle); | ||
expect(context.defaultFormatParsers.whiteSpace).not.toHaveBeenCalled(); | ||
}); | ||
}); |