Skip to content

Commit

Permalink
Merge branch 'master' into u/julairoldi/investigate-image
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi authored Nov 28, 2024
2 parents 119c4dd + 9e9305d commit 9c7f93c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getRootComputedStyleForContext } from '../../coreApi/createEditorContex
import { pasteBlockEntityParser } from '../../override/pasteCopyBlockEntityParser';
import { pasteDisplayFormatParser } from '../../override/pasteDisplayFormatParser';
import { pasteTextProcessor } from '../../override/pasteTextProcessor';
import { pasteWhiteSpaceFormatParser } from '../../override/pasteWhiteSpaceFormatParser';
import type {
ContentModelSegmentFormat,
DomToModelContext,
Expand Down Expand Up @@ -52,6 +53,7 @@ export function createDomToModelContextForSanitizing(
},
formatParserOverride: {
display: pasteDisplayFormatParser,
whiteSpace: pasteWhiteSpaceFormatParser,
},
additionalFormatParsers: {
container: [containerSizeFormatParser],
Expand Down
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);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DomToModelOptionForSanitizing } from 'roosterjs-content-model-types';
import { pasteBlockEntityParser } from '../../../lib/override/pasteCopyBlockEntityParser';
import { pasteDisplayFormatParser } from '../../../lib/override/pasteDisplayFormatParser';
import { pasteTextProcessor } from '../../../lib/override/pasteTextProcessor';
import { pasteWhiteSpaceFormatParser } from '../../../lib/override/pasteWhiteSpaceFormatParser';

describe('createDomToModelContextForSanitizing', () => {
const mockedPasteGeneralProcessor = 'GENERALPROCESSOR' as any;
Expand Down Expand Up @@ -61,6 +62,7 @@ describe('createDomToModelContextForSanitizing', () => {
},
formatParserOverride: {
display: pasteDisplayFormatParser,
whiteSpace: pasteWhiteSpaceFormatParser,
},
additionalFormatParsers: {
container: [containerSizeFormatParser],
Expand Down Expand Up @@ -106,6 +108,7 @@ describe('createDomToModelContextForSanitizing', () => {
},
formatParserOverride: {
display: pasteDisplayFormatParser,
whiteSpace: pasteWhiteSpaceFormatParser,
},
additionalFormatParsers: {
container: [containerSizeFormatParser],
Expand Down
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();
});
});

0 comments on commit 9c7f93c

Please sign in to comment.