Skip to content

Commit b175859

Browse files
committed
fix: flagged toc
1 parent f3b6571 commit b175859

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
});

packages/fern-docs/mdx/src/toc.ts

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ function makeTree(
318318
simpleString: token.title.trim(),
319319
anchorString: token.id.trim(),
320320
children: makeTree(headings, depth + 1),
321+
featureFlags: token.featureFlags,
321322
});
322323
}
323324
} else {

0 commit comments

Comments
 (0)