1+ import { NotionBlock } from "../config/configuration" ;
12import { blocksToMarkdown } from "../TestRun" ;
23import { standardHeadingTransformer } from "./HeadingTransformer" ;
34
4- let blocks : any [ ] ;
5- beforeEach ( ( ) => {
6- blocks = [
5+ test ( "Adds anchor to headings" , async ( ) => {
6+ //setLogLevel("verbose");
7+ const headingBlockId = "86f746f4-1c79-4ba1-a2f6-a1d59c2f9d23" ;
8+ const config = { plugins : [ standardHeadingTransformer ] } ;
9+ const result = await blocksToMarkdown ( config , [
710 {
811 object : "block" ,
9- id : "86f746f4-1c79-4ba1-a2f6-a1d59c2f9d23" ,
10- parent : {
11- type : "page_id" ,
12- page_id : "cc889947-9d05-433f-bf81-012c6808a983" ,
13- } ,
14- created_time : "2023-01-12T21:35:00.000Z" ,
15- last_edited_time : "2023-01-12T21:38:00.000Z" ,
16- created_by : {
17- object : "user" ,
18- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
19- } ,
20- last_edited_by : {
21- object : "user" ,
22- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
23- } ,
24- has_children : false ,
25- archived : false ,
12+ id : headingBlockId ,
2613 type : "heading_1" ,
2714 heading_1 : {
2815 rich_text : [
@@ -44,177 +31,9 @@ beforeEach(() => {
4431 is_toggleable : false ,
4532 color : "default" ,
4633 } ,
47- } ,
48- {
49- object : "block" ,
50- id : "33a17041-bacd-4d94-a50d-9f1359e00690" ,
51- parent : {
52- type : "page_id" ,
53- page_id : "cc889947-9d05-433f-bf81-012c6808a983" ,
54- } ,
55- created_time : "2023-01-12T21:35:00.000Z" ,
56- last_edited_time : "2023-01-12T21:38:00.000Z" ,
57- created_by : {
58- object : "user" ,
59- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
60- } ,
61- last_edited_by : {
62- object : "user" ,
63- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
64- } ,
65- has_children : false ,
66- archived : false ,
67- type : "heading_2" ,
68- heading_2 : {
69- rich_text : [
70- {
71- type : "text" ,
72- text : { content : "Heading Two" , link : null } ,
73- annotations : {
74- bold : false ,
75- italic : false ,
76- strikethrough : false ,
77- underline : false ,
78- code : false ,
79- color : "default" ,
80- } ,
81- plain_text : "Heading Two" ,
82- href : null ,
83- } ,
84- ] ,
85- is_toggleable : false ,
86- color : "default" ,
87- } ,
88- } ,
89- {
90- object : "block" ,
91- id : "35954f5e-68c8-49ff-bbb0-c2540e9ba2d7" ,
92- parent : {
93- type : "page_id" ,
94- page_id : "cc889947-9d05-433f-bf81-012c6808a983" ,
95- } ,
96- created_time : "2023-01-12T21:35:00.000Z" ,
97- last_edited_time : "2023-01-12T21:38:00.000Z" ,
98- created_by : {
99- object : "user" ,
100- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
101- } ,
102- last_edited_by : {
103- object : "user" ,
104- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
105- } ,
106- has_children : false ,
107- archived : false ,
108- type : "heading_3" ,
109- heading_3 : {
110- rich_text : [
111- {
112- type : "text" ,
113- text : { content : "Heading Three" , link : null } ,
114- annotations : {
115- bold : false ,
116- italic : false ,
117- strikethrough : false ,
118- underline : false ,
119- code : false ,
120- color : "default" ,
121- } ,
122- plain_text : "Heading Three" ,
123- href : null ,
124- } ,
125- ] ,
126- is_toggleable : false ,
127- color : "default" ,
128- } ,
129- } ,
130- {
131- object : "block" ,
132- id : "699cb2f4-76f9-4d7a-9ab0-b3de97016b34" ,
133- parent : {
134- type : "page_id" ,
135- page_id : "cc889947-9d05-433f-bf81-012c6808a983" ,
136- } ,
137- created_time : "2023-01-12T21:38:00.000Z" ,
138- last_edited_time : "2023-01-12T21:38:00.000Z" ,
139- created_by : {
140- object : "user" ,
141- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
142- } ,
143- last_edited_by : {
144- object : "user" ,
145- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
146- } ,
147- has_children : false ,
148- archived : false ,
149- type : "paragraph" ,
150- paragraph : { rich_text : [ ] , color : "default" } ,
151- } ,
152- {
153- object : "block" ,
154- id : "71afc2b9-d13a-48e1-8469-1b972d103386" ,
155- parent : {
156- type : "page_id" ,
157- page_id : "cc889947-9d05-433f-bf81-012c6808a983" ,
158- } ,
159- created_time : "2023-01-12T21:38:00.000Z" ,
160- last_edited_time : "2023-01-12T21:38:00.000Z" ,
161- created_by : {
162- object : "user" ,
163- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
164- } ,
165- last_edited_by : {
166- object : "user" ,
167- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
168- } ,
169- has_children : false ,
170- archived : false ,
171- type : "paragraph" ,
172- paragraph : {
173- rich_text : [
174- {
175- type : "text" ,
176- text : {
177- content : "Link to that first heading" ,
178- link : {
179- url : "/cc8899479d05433fbf81012c6808a983#86f746f41c794ba1a2f6a1d59c2f9d23" ,
180- } ,
181- } ,
182- annotations : {
183- bold : false ,
184- italic : false ,
185- strikethrough : false ,
186- underline : false ,
187- code : false ,
188- color : "default" ,
189- } ,
190- plain_text : "Link to that first heading" ,
191- href : "/cc8899479d05433fbf81012c6808a983#86f746f41c794ba1a2f6a1d59c2f9d23" ,
192- } ,
193- ] ,
194- color : "default" ,
195- } ,
196- } ,
197- {
198- object : "block" ,
199- id : "72fb739e-7fd9-42d9-abda-1d3de3fe2a38" ,
200- parent : {
201- type : "page_id" ,
202- page_id : "cc889947-9d05-433f-bf81-012c6808a983" ,
203- } ,
204- created_time : "2023-01-12T21:38:00.000Z" ,
205- last_edited_time : "2023-01-12T21:38:00.000Z" ,
206- created_by : {
207- object : "user" ,
208- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
209- } ,
210- last_edited_by : {
211- object : "user" ,
212- id : "11fb7f16-0560-4aee-ab88-ed75a850cfc4" ,
213- } ,
214- has_children : false ,
215- archived : false ,
216- type : "paragraph" ,
217- paragraph : { rich_text : [ ] , color : "default" } ,
218- } ,
219- ] ;
34+ } as unknown as NotionBlock ,
35+ ] ) ;
36+ expect ( result . trim ( ) ) . toBe (
37+ `# Heading One {#${ headingBlockId . replaceAll ( "-" , "" ) } }`
38+ ) ;
22039} ) ;
0 commit comments