@@ -20,24 +20,48 @@ export default function rehypeSectionWrapper() {
2020 newChildren . push ( wrapper ) ;
2121 return wrapper ;
2222 } ;
23-
23+
2424 for ( const node of tree . children ) {
25- // Check if the node is an H2 element
25+ // Check if the node is an H1 element
26+ if ( node . type === 'element' && node . tagName === 'h1' ) {
27+ // 1. Extract the text content of the H2.
28+ const headerText = toString ( node ) ;
29+
30+ // 2. Create a new <Header> component element with a 'title' prop.
31+ const headerComponent = h ( 'div.outer-wrapper' , [ h ( 'div.middle-wrapper' ,
32+ [ h ( 'h1.h1-wrapper' , headerText ) , h ( 'div.inter-wrapper' , [ ] ) ] ) ] ) ;
33+
34+ // 3. Add the new <Header> component to the wrapper.
35+ newChildren . push ( h ( 'br' , [ ] ) ) ; // Add a horizontal rule before the header
36+ newChildren . push ( headerComponent ) ;
37+ newChildren . push ( h ( 'br' , [ ] ) ) ;
38+ currentWrapper = createNewWrapper ( ) ;
39+ continue ;
40+ }
41+
2642 if ( node . type === 'element' && node . tagName === 'h2' ) {
27- // 2 . Extract the text content of the H2.
43+ // 1 . Extract the text content of the H2.
2844 const headerText = toString ( node ) ;
2945
30- // 3. Create a new <Header> component element with a 'title' prop.
31- const headerComponent = h ( 'h1.title' , headerText ) ;
46+ // 2. Create a new <Header> component element with a 'title' prop.
47+ const headerComponent = h ( 'div.outer-wrapper' , [ h ( 'div.middle-wrapper' ,
48+ [ h ( 'div.inter-wrapper' , [ h ( 'h2.h2-wrapper' , headerText ) ] ) ] ) ] )
3249
33- // 4. Add the new <Header> component to the wrapper.
50+ // 3. Add the new <Header> component to the wrapper.
51+ newChildren . push ( h ( 'br' , [ ] ) ) ; // Add a horizontal rule before the header
3452 newChildren . push ( headerComponent ) ;
53+ newChildren . push ( h ( 'br' , [ ] ) ) ;
3554 currentWrapper = createNewWrapper ( ) ;
36- // 5. Continue to the next node, effectively *discarding* the original H2.
37- // 6. It's an H2, so stop previous section wrapper.
3855 continue ;
3956 }
57+ if ( node . type === 'element' && node . tagName === 'hr' ) {
4058
59+
60+ // 4. Add the new <Header> component to the wrapper.
61+ newChildren . push ( h ( 'br' , [ ] ) ) ; // Add a horizontal rule before the header
62+ currentWrapper = null ;
63+ continue ;
64+ }
4165 // If there's no active wrapper, create one.
4266 if ( ! currentWrapper ) {
4367 currentWrapper = createNewWrapper ( ) ;
0 commit comments