1
- import { Node , Parent } from "unist"
2
1
import { highlight } from "../highlighter"
3
2
import { extractLinks } from "./links"
4
3
import {
@@ -16,15 +15,16 @@ import {
16
15
extractJSXAnnotations ,
17
16
} from "./annotations"
18
17
import { mergeFocus } from "../utils"
18
+ import { CodeNode , SuperNode } from "./nodes"
19
19
20
20
export async function transformCodeNodes (
21
- tree : Node ,
21
+ tree : SuperNode ,
22
22
{ theme } : { theme : any }
23
23
) {
24
24
await visitAsync (
25
25
tree ,
26
26
"code" ,
27
- async ( node , index , parent ) => {
27
+ async ( node : CodeNode , index , parent ) => {
28
28
await transformCode (
29
29
{ node, index, parent : parent ! } ,
30
30
{ theme }
@@ -33,7 +33,7 @@ export async function transformCodeNodes(
33
33
)
34
34
}
35
35
36
- export function isEditorNode ( node : Node ) {
36
+ export function isEditorNode ( node : SuperNode ) {
37
37
return (
38
38
node . type === "code" ||
39
39
( node . type === "mdxJsxFlowElement" &&
@@ -42,7 +42,7 @@ export function isEditorNode(node: Node) {
42
42
}
43
43
44
44
async function transformCode (
45
- nodeInfo : NodeInfo ,
45
+ nodeInfo : NodeInfo < CodeNode > ,
46
46
config : { theme : any }
47
47
) {
48
48
toJSX ( nodeInfo . node , {
@@ -66,14 +66,14 @@ export async function mapAnyCodeNode(
66
66
) {
67
67
const { node } = nodeInfo
68
68
if ( node . type === "code" ) {
69
- return mapCode ( nodeInfo , config )
69
+ return mapCode ( nodeInfo as NodeInfo < CodeNode > , config )
70
70
} else {
71
71
return mapEditor ( nodeInfo , config )
72
72
}
73
73
}
74
74
75
75
async function mapCode (
76
- nodeInfo : NodeInfo ,
76
+ nodeInfo : NodeInfo < CodeNode > ,
77
77
config : { theme : any }
78
78
) : Promise < EditorProps > {
79
79
const file = await mapFile ( nodeInfo , config )
@@ -94,19 +94,23 @@ export async function mapEditor(
94
94
config : { theme : any }
95
95
) : Promise < EditorProps > {
96
96
const [ northNodes , southNodes = [ ] ] = splitChildren (
97
- node as Parent ,
97
+ node ,
98
98
"thematicBreak"
99
99
)
100
100
101
101
const northFiles = await Promise . all (
102
102
northNodes
103
103
. filter ( ( { node } ) => node . type === "code" )
104
- . map ( nodeInfo => mapFile ( nodeInfo , config ) )
104
+ . map ( ( nodeInfo : NodeInfo < CodeNode > ) =>
105
+ mapFile ( nodeInfo , config )
106
+ )
105
107
)
106
108
const southFiles = await Promise . all (
107
109
southNodes
108
110
. filter ( ( { node } ) => node . type === "code" )
109
- . map ( nodeInfo => mapFile ( nodeInfo , config ) )
111
+ . map ( ( nodeInfo : NodeInfo < CodeNode > ) =>
112
+ mapFile ( nodeInfo , config )
113
+ )
110
114
)
111
115
const allFiles = [ ...northFiles , ...southFiles ]
112
116
const northActive =
@@ -141,7 +145,7 @@ export async function mapEditor(
141
145
}
142
146
143
147
async function mapFile (
144
- { node, index, parent } : NodeInfo ,
148
+ { node, index, parent } : NodeInfo < CodeNode > ,
145
149
config : { theme : any }
146
150
) : Promise < CodeStep & FileOptions & { name : string } > {
147
151
const { theme } = config
0 commit comments