@@ -6,27 +6,28 @@ import type * as mdast from 'mdast';
66import type { TOCOptions , VFile } from '../shared/vfile' ;
77
88export function tocPlugin ( options ?: TOCOptions ) {
9- return ( tree : mdast . Root , vfile : VFile ) => {
10- const _options = {
11- ...options ,
12- ...( vfile . data ?. tocOptions || { } )
13- } ;
9+ return ( tree : mdast . Root , vfile : VFile ) => {
10+ const _options = {
11+ ...options ,
12+ ...( vfile . data ?. tocOptions || { } )
13+ } ;
1414
15- const result = toc ( tree , _options ) ;
15+ const result = toc ( tree , _options ) ;
1616
17- tree . children = [ ] . concat (
18- tree . children . slice ( 0 , result . index ) ,
19- result . map || [ ]
20- ) ;
17+ tree . children = [ ] . concat (
18+ tree . children . slice ( 0 , result . index ) ,
19+ result . map || [ ]
20+ ) ;
2121
22- return visit ( tree , 'listItem' , ( node : any , index : number , parent : any ) => {
23- if ( node . children . length > 1 ) {
24- node . data = node . data || { } ;
25- node . data . hProperties = node . data . hProperties || { } ;
26- node . data . hProperties . class = node . data . hProperties . class || [ ] ;
27- node . data . hProperties . class . push ( 'has-children' ) ;
28- }
29- return true ;
30- } ) ;
31- } ;
22+ return visit ( tree , 'listItem' , ( node : any , index : number , parent : any ) => {
23+ if ( node . children . length > 1 ) {
24+ node . data = node . data || { } ;
25+ node . data . title = node . data . title || '无标题' ;
26+ node . data . hProperties = node . data . hProperties || { } ;
27+ node . data . hProperties . class = node . data . hProperties . class || [ ] ;
28+ node . data . hProperties . class . push ( 'has-children' ) ;
29+ }
30+ return true ;
31+ } ) ;
32+ } ;
3233}
0 commit comments