File tree 2 files changed +55
-0
lines changed
packages/fern-docs/mdx/src
2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { toTree } from "../parse" ;
2
+ import { makeToc } from "../toc" ;
3
+
4
+ describe ( "toc" , ( ) => {
5
+ it ( "should create a toc" , ( ) => {
6
+ const toc = makeToc ( toTree ( `# Hello world` ) . hast ) ;
7
+ expect ( toc ) . toEqual ( [
8
+ {
9
+ simpleString : "Hello world" ,
10
+ anchorString : "hello-world" ,
11
+ children : [ ] ,
12
+ } ,
13
+ ] ) ;
14
+ } ) ;
15
+
16
+ it ( "should create a toc with a nested heading" , ( ) => {
17
+ const toc = makeToc ( toTree ( `# Hello world\n\n## Nested heading` ) . hast ) ;
18
+ expect ( toc ) . toEqual ( [
19
+ {
20
+ simpleString : "Hello world" ,
21
+ anchorString : "hello-world" ,
22
+ children : [
23
+ {
24
+ simpleString : "Nested heading" ,
25
+ anchorString : "nested-heading" ,
26
+ children : [ ] ,
27
+ } ,
28
+ ] ,
29
+ } ,
30
+ ] ) ;
31
+ } ) ;
32
+
33
+ it ( "should create a toc with feature flags" , ( ) => {
34
+ const toc = makeToc (
35
+ toTree (
36
+ `<Feature flag="test" fallbackValue="false" match="true">\n# Hello world\n</Feature>`
37
+ ) . hast
38
+ ) ;
39
+ expect ( toc ) . toEqual ( [
40
+ {
41
+ simpleString : "Hello world" ,
42
+ anchorString : "hello-world" ,
43
+ featureFlags : [
44
+ {
45
+ flag : "test" ,
46
+ fallbackValue : "false" ,
47
+ match : "true" ,
48
+ } ,
49
+ ] ,
50
+ children : [ ] ,
51
+ } ,
52
+ ] ) ;
53
+ } ) ;
54
+ } ) ;
Original file line number Diff line number Diff line change @@ -318,6 +318,7 @@ function makeTree(
318
318
simpleString : token . title . trim ( ) ,
319
319
anchorString : token . id . trim ( ) ,
320
320
children : makeTree ( headings , depth + 1 ) ,
321
+ featureFlags : token . featureFlags ,
321
322
} ) ;
322
323
}
323
324
} else {
You can’t perform that action at this time.
0 commit comments