File tree Expand file tree Collapse file tree 3 files changed +39
-37
lines changed Expand file tree Collapse file tree 3 files changed +39
-37
lines changed Original file line number Diff line number Diff line change @@ -198,16 +198,27 @@ export function extractJSXAnnotations(
198
198
"mdxJsxFlowElement" &&
199
199
parent . children [ nextIndex ] . name === "CH.Annotation"
200
200
) {
201
- const { attributes } = parent . children [ nextIndex ] as any
201
+ const jsxAnnotation = parent . children [ nextIndex ] as any
202
+
203
+ // copy attributes to props
202
204
const props = { } as any
203
- attributes . forEach ( ( attr : any ) => {
205
+ jsxAnnotation . attributes . forEach ( ( attr : any ) => {
204
206
props [ attr . name ] = attr . value
205
207
} )
206
208
const { as, focus, ...data } = props
209
+
207
210
const Component = annotationsMap [ as ] || as
208
- annotations . push ( { Component, focus, data } )
209
- console . log ( parent . children [ nextIndex ] )
211
+ annotations . push ( {
212
+ Component,
213
+ focus,
214
+ data : isEmpty ( data ) ? undefined : data ,
215
+ } )
216
+ // console.log(jsxAnnotation)
210
217
parent . children . splice ( nextIndex , 1 )
211
218
}
212
219
return annotations
213
220
}
221
+
222
+ function isEmpty ( obj : any ) {
223
+ return Object . keys ( obj ) . length === 0
224
+ }
Original file line number Diff line number Diff line change @@ -67,6 +67,25 @@ export function isEditorNode(node: Node) {
67
67
)
68
68
}
69
69
70
+ async function transformCode (
71
+ nodeInfo : NodeInfo ,
72
+ config : { theme : any }
73
+ ) {
74
+ toJSX ( nodeInfo . node , {
75
+ name : "CH.Code" ,
76
+ props : await mapCode ( nodeInfo , config ) ,
77
+ } )
78
+ }
79
+ export async function transformEditor (
80
+ nodeInfo : NodeInfo ,
81
+ config : { theme : any }
82
+ ) {
83
+ toJSX ( nodeInfo . node , {
84
+ name : "CH.Code" ,
85
+ props : await mapEditor ( nodeInfo , config ) ,
86
+ } )
87
+ }
88
+
70
89
export async function mapAnyCodeNode (
71
90
nodeInfo : NodeInfo ,
72
91
config : { theme : any }
@@ -98,39 +117,6 @@ async function mapCode(
98
117
return props
99
118
}
100
119
101
- async function transformCode (
102
- nodeInfo : NodeInfo ,
103
- config : { theme : any }
104
- ) {
105
- const file = await mapFile ( nodeInfo , config )
106
- const props = {
107
- northPanel : {
108
- tabs : [ file . name ] ,
109
- active : file . name ,
110
- heightRatio : 1 ,
111
- } ,
112
- files : [ file ] ,
113
- codeConfig : {
114
- theme : config . theme ,
115
- } ,
116
- }
117
- toJSX ( nodeInfo . node , {
118
- name : "CH.Code" ,
119
- props,
120
- } )
121
- }
122
- export async function transformEditor (
123
- nodeInfo : NodeInfo ,
124
- config : { theme : any }
125
- ) {
126
- const props = await mapEditor ( nodeInfo , config )
127
-
128
- toJSX ( nodeInfo . node , {
129
- name : "CH.Code" ,
130
- props,
131
- } )
132
- }
133
-
134
120
export async function mapEditor (
135
121
{ node } : NodeInfo ,
136
122
config : { theme : any }
Original file line number Diff line number Diff line change @@ -19,3 +19,8 @@ function adipiscing(...elit) {
19
19
url = " https://github.com/code-hike"
20
20
title = " Code Hike"
21
21
/>
22
+ <CH.Annotation as = " label" focus = " 8" >
23
+
24
+ ** Hello**
25
+
26
+ </CH.Annotation >
You can’t perform that action at this time.
0 commit comments