@@ -34,17 +34,24 @@ const plugin: Plugin = function plugin(
34
34
const { toString} = await import ( 'mdast-util-to-string' ) ;
35
35
const { visit, EXIT } = await import ( 'unist-util-visit' ) ;
36
36
37
- visit ( root , 'heading' , ( headingNode : Heading , index , parent ) => {
38
- if ( headingNode . depth === 1 ) {
39
- vfile . data . contentTitle = toString ( headingNode ) ;
40
- if ( removeContentTitle ) {
41
- // @ts -expect-error: TODO how to fix?
42
- parent ! . children . splice ( index , 1 ) ;
37
+ visit ( root , [ 'heading' , 'thematicBreak' ] , ( node , index , parent ) => {
38
+ if ( node . type === 'heading' ) {
39
+ const headingNode = node as Heading ;
40
+ if ( headingNode . depth === 1 ) {
41
+ vfile . data . contentTitle = toString ( headingNode ) ;
42
+ if ( removeContentTitle ) {
43
+ // @ts -expect-error: TODO how to fix?
44
+ parent ! . children . splice ( index , 1 ) ;
45
+ }
46
+ return EXIT ; // We only handle the very first heading
47
+ }
48
+ // We only handle contentTitle if it's the very first heading found
49
+ if ( headingNode . depth >= 1 ) {
50
+ return EXIT ;
43
51
}
44
- return EXIT ; // We only handle the very first heading
45
52
}
46
- // We only handle contentTitle if it's the very first heading found
47
- if ( headingNode . depth >= 1 ) {
53
+ // We only handle contentTitle when it's above the first thematic break
54
+ if ( node . type === 'thematicBreak' ) {
48
55
return EXIT ;
49
56
}
50
57
return undefined ;
0 commit comments