1- // plugins/remark-custom-blocks.js
2- // VERSION BEFORE anchorId/slug logic was added
3-
41const { visit } = require ( 'unist-util-visit' ) ;
52
63// --- Helper Functions ---
@@ -23,26 +20,19 @@ const plugin = (options) => {
2320
2421 // Target JSX elements in the AST
2522 visit ( tree , 'mdxJsxFlowElement' , ( node , index , parent ) => {
26- // Look specifically for the <VerticlStepper> tag used in Markdown source (as originally written)
27- if ( node . name === 'VerticalStepper' ) { // <-- Checks for VerticalStepper from original code
23+ // Look specifically for the <VerticlStepper> tag used in the markdown file
24+ if ( node . name === 'VerticalStepper' ) {
2825 try {
29- console . log ( 'Processing VStepper tag' ) ; // Log from original code
30-
31- // --- 1. Parse <VStepper> Attributes ---
26+ // --- 1. Parse <VerticalStepper> Attributes ---
3227 const jsxAttributes = node . attributes || [ ] ;
3328 let type = "numbered" ; // Default type
34- let isExpanded = false ; // Default not expanded (allExpanded)
29+ let isExpanded = true ;
3530
3631 // Extract attributes
3732 jsxAttributes . forEach ( attr => {
3833 if ( attr . type === 'mdxJsxAttribute' ) {
3934 if ( attr . name === 'type' && typeof attr . value === 'string' ) {
4035 type = attr . value ;
41- console . log ( `Found type: ${ type } ` ) ; // Log from original code
42- }
43- else if ( attr . name === 'allExpanded' ) { // Check for allExpanded
44- isExpanded = true ;
45- console . log ( 'Found allExpanded attribute' ) ; // Log from original code
4636 }
4737 }
4838 } ) ;
@@ -69,13 +59,12 @@ const plugin = (options) => {
6959
7060 if ( node . children && node . children . length > 0 ) {
7161 node . children . forEach ( ( child ) => {
72- console . log ( child )
7362 if ( child . type === 'heading' && child . depth === 2 ) {
7463 finalizeStep ( ) ; // Finalize the previous step first
7564 currentStepLabel = extractText ( child . children ) ;
7665 currentAnchorId = child . data . hProperties . id ;
7766 currentStepId = `step-${ stepsData . length + 1 } ` ; // Generate step-X ID
78- console . log ( `Found heading: ${ currentStepLabel } \{# ${ currentAnchorId } \}` ) ; // Log from original code
67+ currentStepContent . push ( child ) ; // We need the header otherwise onBrokenAnchors fails
7968 } else if ( currentStepLabel ) {
8069 // Only collect content nodes *after* a heading has defined a step
8170 currentStepContent . push ( child ) ;
@@ -84,14 +73,12 @@ const plugin = (options) => {
8473 }
8574 finalizeStep ( ) ; // Finalize the last step found
8675
87- console . log ( `Found ${ stepsData . length } steps` ) ; // Log from original code
88-
8976 // --- 3. Transform Parent Node ---
90- // Transforms to VerticalStepper to match MDXComponents.js
77+ // Transforms to <Stepper/> to match src/theme/ MDXComponents.js
9178 node . name = 'Stepper' ;
9279 node . children = [ ] ; // Clear original children
9380
94- // Set attributes - type and expanded (if isExpanded is true)
81+ // Set attributes
9582 node . attributes = [
9683 { type : 'mdxJsxAttribute' , name : 'type' , value : type } ,
9784 ] ;
@@ -122,44 +109,13 @@ const plugin = (options) => {
122109 } ) ;
123110 }
124111
125- const anchorElement = {
126- type : 'mdxJsxFlowElement' ,
127- name : 'a' ,
128- attributes : [
129- { type : 'mdxJsxAttribute' , name : 'href' , value : `#${ step . anchorId } ` } ,
130- { type : 'mdxJsxAttribute' , name : 'className' , value : 'hash-link' }
131- ] ,
132- children : [
133- // Add a link symbol or text
134- {
135- type : 'text' ,
136- value : '🔗' // Or any other symbol/text you prefer
137- }
138- ]
139- } ;
140-
141- const contentWithAnchor = [
142- {
143- type : 'mdxJsxFlowElement' ,
144- name : 'div' ,
145- attributes : [
146- { type : 'mdxJsxAttribute' , name : 'id' , value : step . anchorId }
147- ] ,
148- children : [
149- anchorElement , // Add the anchor element
150- ...step . content // Then add the regular content
151- ]
152- }
153- ] ;
154-
155112 // Push the Step node
156113 node . children . push ( {
157114 type : 'mdxJsxFlowElement' ,
158115 name : 'Step' , // Output Step tag
159116 attributes : stepAttributes ,
160- children : contentWithAnchor , // Pass content nodes as children
117+ children : [ ... step . content ] , // Pass content nodes as children
161118 } ) ;
162- console . log ( `Added step: ${ step . label } with anchorId: ${ step . anchorId || 'none' } ` ) ; // Log from original code
163119 } ) ;
164120 } catch ( error ) {
165121 const filePath = file ?. path || 'unknown file' ;
@@ -172,4 +128,4 @@ const plugin = (options) => {
172128 return transformer ;
173129} ;
174130
175- module . exports = plugin ;
131+ module . exports = plugin ;
0 commit comments