File tree Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,14 @@ function stylesFromAttrs(attrs?: JSONContent['attrs']) {
1515 case 'textAlign' :
1616 style . textAlign = value
1717 break
18+ case 'color' :
19+ if ( value )
20+ style . color = value
21+ break
22+ case 'backgroundColor' :
23+ if ( value )
24+ style . backgroundColor = value
25+ break
1826 case 'fontFamily' :
1927 if ( value )
2028 style . fontFamily = value
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest'
2+ import { mount } from '@vue/test-utils'
3+ import { defineComponent } from 'vue'
4+ import type { JSONContent } from '../../src'
5+ import { JsonRenderer } from '../../src'
6+
7+ const WrappedJsonRenderer = defineComponent ( {
8+ components : { JsonRenderer } ,
9+ props : {
10+ content : {
11+ type : Object as ( ) => JSONContent ,
12+ required : true ,
13+ } ,
14+ } ,
15+ template : '<JsonRenderer v-bind="$props" />' ,
16+ } )
17+
18+ describe ( 'jsonRenderer background color support' , ( ) => {
19+ it ( 'renders text with inline background color from textStyle mark' , ( ) => {
20+ const wrapper = mount ( WrappedJsonRenderer , {
21+ props : {
22+ content : {
23+ type : 'doc' ,
24+ content : [
25+ {
26+ type : 'paragraph' ,
27+ content : [
28+ {
29+ type : 'text' ,
30+ text : 'highlighted' ,
31+ marks : [
32+ {
33+ type : 'textStyle' ,
34+ attrs : { backgroundColor : '#ffee99' } ,
35+ } ,
36+ ] ,
37+ } ,
38+ ] ,
39+ } ,
40+ ] ,
41+ } ,
42+ } ,
43+ } )
44+
45+ const el = wrapper . find ( 'span' ) . element as HTMLElement
46+ const styleAttr = el . getAttribute ( 'style' ) || ''
47+ expect ( styleAttr ) . toMatch ( / b a c k g r o u n d - c o l o r : \s * ( # f f e e 9 9 | r g b \( ) / )
48+ } )
49+ } )
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest'
2+ import { mount } from '@vue/test-utils'
3+ import { defineComponent } from 'vue'
4+ import type { JSONContent } from '../../src'
5+ import { JsonRenderer } from '../../src'
6+
7+ const WrappedJsonRenderer = defineComponent ( {
8+ components : { JsonRenderer } ,
9+ props : {
10+ content : {
11+ type : Object as ( ) => JSONContent ,
12+ required : true ,
13+ } ,
14+ } ,
15+ template : '<JsonRenderer v-bind="$props" />' ,
16+ } )
17+
18+ describe ( 'jsonRenderer color support' , ( ) => {
19+ it ( 'renders text with inline color from textStyle mark' , ( ) => {
20+ const wrapper = mount ( WrappedJsonRenderer , {
21+ props : {
22+ content : {
23+ type : 'doc' ,
24+ content : [
25+ {
26+ type : 'paragraph' ,
27+ content : [
28+ {
29+ type : 'text' ,
30+ text : 'colored' ,
31+ marks : [
32+ {
33+ type : 'textStyle' ,
34+ attrs : { color : '#5dc2da' } ,
35+ } ,
36+ ] ,
37+ } ,
38+ ] ,
39+ } ,
40+ ] ,
41+ } ,
42+ } ,
43+ } )
44+
45+ const el = wrapper . find ( 'span' ) . element as HTMLElement
46+ // Check that color style is applied (jsdom may normalize to rgb)
47+ const styleAttr = el . getAttribute ( 'style' ) || ''
48+ expect ( styleAttr ) . toMatch ( / c o l o r : \s * ( # 5 d c 2 d a | r g b \( ) / )
49+ } )
50+ } )
You can’t perform that action at this time.
0 commit comments