Skip to content

Commit 0220f54

Browse files
committed
add comments to describe logic
1 parent 77166cd commit 0220f54

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/components/MDXComponents/MDXHeading.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ export const MDXHeading = (props) => {
66
const { level, children } = props;
77
let href = '';
88

9+
/* Test if children element is not a string before creating the url slug */
910
if (children && typeof children != 'string') {
1011
let newChildren = '';
12+
/* Test if child element is a single object */
1113
if (typeof children == 'object' && children.props?.children) {
1214
newChildren = children.props.children;
1315
} else {
16+
/* If not a single object, we expect an array of
17+
elements and loop through them */
1418
for (let i = 0; i < children.length; i++) {
1519
if (typeof children[i] == 'string') {
1620
newChildren = newChildren + children[i];
@@ -21,6 +25,7 @@ export const MDXHeading = (props) => {
2125
}
2226
href = `${slug(newChildren)}`;
2327
} else {
28+
/* If children element is a string, use that to create the url slug */
2429
href = `${slug(children)}`;
2530
}
2631

0 commit comments

Comments
 (0)