@@ -18,6 +18,8 @@ const extractText = (nodes) => {
18
18
const plugin = ( options ) => {
19
19
const transformer = ( tree , file ) => {
20
20
21
+ let total_steps = 0 ; // Keep track of the total number of steps
22
+
21
23
// Target JSX elements in the AST
22
24
visit ( tree , 'mdxJsxFlowElement' , ( node , index , parent ) => {
23
25
// Look specifically for the <VerticalStepper> tag used in the markdown file
@@ -27,12 +29,16 @@ const plugin = (options) => {
27
29
const jsxAttributes = node . attributes || [ ] ;
28
30
let type = "numbered" ; // Default type
29
31
let isExpanded = true ;
32
+ let headerLevel = 2 ;
30
33
31
34
// Extract attributes
32
35
jsxAttributes . forEach ( attr => {
33
36
if ( attr . type === 'mdxJsxAttribute' ) {
34
37
if ( attr . name === 'type' && typeof attr . value === 'string' ) {
35
38
type = attr . value ;
39
+ } else if ( attr . name === 'headerLevel' && typeof attr . value === 'string' ) {
40
+ if ( attr . value === "h3" )
41
+ headerLevel = 3
36
42
}
37
43
}
38
44
} ) ;
@@ -52,18 +58,19 @@ const plugin = (options) => {
52
58
anchorId : currentAnchorId ,
53
59
content : [ ...currentStepContent ] ,
54
60
} ) ;
61
+ total_steps ++ ;
55
62
}
56
63
currentStepContent = [ ] ;
57
64
currentStepLabel = null ; // Reset label
58
65
} ;
59
66
60
67
if ( node . children && node . children . length > 0 ) {
61
68
node . children . forEach ( ( child ) => {
62
- if ( child . type === 'heading' && child . depth === 2 ) {
69
+ if ( child . type === 'heading' && child . depth === headerLevel ) {
63
70
finalizeStep ( ) ; // Finalize the previous step first
64
71
currentStepLabel = extractText ( child . children ) ;
65
72
currentAnchorId = child . data . hProperties . id ;
66
- currentStepId = `step-${ stepsData . length + 1 } ` ; // Generate step-X ID
73
+ currentStepId = `step-${ total_steps } ` ; // Generate step-X ID
67
74
currentStepContent . push ( child ) ; // We need the header otherwise onBrokenAnchors fails
68
75
} else if ( currentStepLabel ) {
69
76
// Only collect content nodes *after* a heading has defined a step
@@ -81,6 +88,7 @@ const plugin = (options) => {
81
88
// Set attributes
82
89
node . attributes = [
83
90
{ type : 'mdxJsxAttribute' , name : 'type' , value : type } ,
91
+ { type : 'mdxJsxAttribute' , name : 'headerLevel' , value : headerLevel } ,
84
92
] ;
85
93
if ( isExpanded ) {
86
94
node . attributes . push ( {
0 commit comments