From 38c1d68ad0b0bdbc3637a811dcb77880b6adb7d6 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Wed, 29 Jan 2025 19:42:45 +0000 Subject: [PATCH] generate headings which only consist of code --- .../MdxProvider/MdxTitle/MdxTitle.tsx | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/apps/documentation/src/components/MdxProvider/MdxTitle/MdxTitle.tsx b/apps/documentation/src/components/MdxProvider/MdxTitle/MdxTitle.tsx index 0f5c040c..1576c8b1 100644 --- a/apps/documentation/src/components/MdxProvider/MdxTitle/MdxTitle.tsx +++ b/apps/documentation/src/components/MdxProvider/MdxTitle/MdxTitle.tsx @@ -4,7 +4,7 @@ import { Title, type TitleProps } from '@mantine/core' export default function MdxTitle(props: TitleProps): JSX.Element { return ( { - if (typeof child === 'string') { - return child - } - if (typeof child === 'object' && child !== null && 'props' in child) { - const childWithProps = child as { props?: { children?: ReactNode } } - return typeof childWithProps.props?.children === 'string' - ? childWithProps.props.children - : '' - } - return '' - }) - .join('') + const getTextContent = (node: ReactNode): string => { + if (typeof node === 'string') return node + if (typeof node === 'object' && node !== null && 'props' in node) { + const child = node as { props?: { children?: ReactNode } } + return getTextContent(child.props?.children) + } + return '' + } + if (Array.isArray(children)) { + const result = children.map(getTextContent).join('') return result.toLowerCase().replace(/\s+/g, '-') } - return typeof children === 'string' - ? children.toLowerCase().replace(/\s+/g, '-') - : '' + const textContent = getTextContent(children) + return textContent.toLowerCase().replace(/\s+/g, '-') } export const h = (order: 1 | 2 | 3 | 4 | 5 | 6): ElementType<TitleProps> => {