File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,40 @@ const excludes = [
31
31
* @returns {string } an string with the name of the section related with the input heading
32
32
*/
33
33
function getSectionNameFromHeadingContent ( children ) {
34
- return children [ 0 ] . value ; // Get the name of the subsection
34
+ const walk = ( children , depth ) =>
35
+ children . reduce ( ( text , node , index ) => {
36
+ if ( ! node || ! node . type ) return text ;
37
+ switch ( node . type ) {
38
+ //
39
+ // meaningfull nodes
40
+ //
41
+ case "emphasis" :
42
+ text += "_" + walk ( node . children , depth + 1 ) + "_" ;
43
+ break ;
44
+ case "inlineCode" :
45
+ text += "`" + node . value + "`" ;
46
+ break ;
47
+ case "strong" :
48
+ text += "**" + walk ( node . children , depth + 1 ) + "**" ;
49
+ break ;
50
+ case "text" :
51
+ text += node . value ;
52
+ break ;
53
+ //
54
+ // skipped nodes
55
+ //
56
+ case "heading" :
57
+ case "html" :
58
+ case "link" :
59
+ case "list" :
60
+ case "paragraph" :
61
+ default :
62
+ break ;
63
+ }
64
+ return text ;
65
+ } , "" ) ;
66
+
67
+ return walk ( children , 0 ) ;
35
68
}
36
69
37
70
/**
You can’t perform that action at this time.
0 commit comments