-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ccf2f7
commit 6228d4b
Showing
5 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...ges-content-model/roosterjs-content-model-core/lib/override/pasteTextColorFormatParser.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 { ContentModelSegmentFormat, FormatParser } from 'roosterjs-content-model-types'; | ||
|
||
const VAR_PREFIX = 'var('; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const pasteTextColorFormatParser: FormatParser<ContentModelSegmentFormat> = ( | ||
format, | ||
element, | ||
context, | ||
defaultStyle | ||
): void => { | ||
if (!element.style.color.startsWith(VAR_PREFIX)) { | ||
context.defaultFormatParsers.textColor?.(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
83 changes: 83 additions & 0 deletions
83
...ntent-model/roosterjs-content-model-core/test/overrides/pasteTextColorFormatParserTest.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,83 @@ | ||
import { pasteTextColorFormatParser } from '../../lib/override/pasteTextColorFormatParser'; | ||
|
||
describe('pasteTextColorFormatParser', () => { | ||
it('Do not handle', () => { | ||
const element = document.createElement('div'); | ||
element.style.color = 'var(--variable)'; | ||
const format = {}; | ||
const textColorSpy = jasmine.createSpy('defaultTextColorParser'); | ||
|
||
pasteTextColorFormatParser( | ||
format, | ||
element, | ||
<any>{ | ||
defaultFormatParsers: { | ||
textColor: textColorSpy, | ||
}, | ||
}, | ||
<any>{} | ||
); | ||
|
||
expect(textColorSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('Handle, name based color', () => { | ||
const element = document.createElement('div'); | ||
element.style.color = 'white'; | ||
const format = {}; | ||
const textColorSpy = jasmine.createSpy('defaultTextColorParser'); | ||
|
||
pasteTextColorFormatParser( | ||
format, | ||
element, | ||
<any>{ | ||
defaultFormatParsers: { | ||
textColor: textColorSpy, | ||
}, | ||
}, | ||
<any>{} | ||
); | ||
|
||
expect(textColorSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('Handle, rgb color', () => { | ||
const element = document.createElement('div'); | ||
element.style.color = 'rgb(77,77,77)'; | ||
const format = {}; | ||
const textColorSpy = jasmine.createSpy('defaultTextColorParser'); | ||
|
||
pasteTextColorFormatParser( | ||
format, | ||
element, | ||
<any>{ | ||
defaultFormatParsers: { | ||
textColor: textColorSpy, | ||
}, | ||
}, | ||
<any>{} | ||
); | ||
|
||
expect(textColorSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('Handle, rgb color', () => { | ||
const element = document.createElement('div'); | ||
element.style.color = '#FFF'; | ||
const format = {}; | ||
const textColorSpy = jasmine.createSpy('defaultTextColorParser'); | ||
|
||
pasteTextColorFormatParser( | ||
format, | ||
element, | ||
<any>{ | ||
defaultFormatParsers: { | ||
textColor: textColorSpy, | ||
}, | ||
}, | ||
<any>{} | ||
); | ||
|
||
expect(textColorSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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