File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
src/components/MDXComponents Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,15 @@ export const MDXHeading = (props) => {
6
6
const { level, children } = props ;
7
7
let href = '' ;
8
8
9
+ /* Test if children element is not a string before creating the url slug */
9
10
if ( children && typeof children != 'string' ) {
10
11
let newChildren = '' ;
12
+ /* Test if child element is a single object */
11
13
if ( typeof children == 'object' && children . props ?. children ) {
12
14
newChildren = children . props . children ;
13
15
} else {
16
+ /* If not a single object, we expect an array of
17
+ elements and loop through them */
14
18
for ( let i = 0 ; i < children . length ; i ++ ) {
15
19
if ( typeof children [ i ] == 'string' ) {
16
20
newChildren = newChildren + children [ i ] ;
@@ -21,6 +25,7 @@ export const MDXHeading = (props) => {
21
25
}
22
26
href = `${ slug ( newChildren ) } ` ;
23
27
} else {
28
+ /* If children element is a string, use that to create the url slug */
24
29
href = `${ slug ( children ) } ` ;
25
30
}
26
31
You can’t perform that action at this time.
0 commit comments