update id gen

This commit is contained in:
Jacob Marshall
2025-01-29 22:45:15 +00:00
committed by GitHub
parent 90ee21b577
commit 88ab0538d9
@@ -29,7 +29,15 @@ function getIdFrom(children: ReactNode): string {
? children.map(getTextContent).join('')
: getTextContent(children)
return textContent.toLowerCase().replace(/[\s\W_]+/g, '-')
return textContent
.normalize('NFKD') // separate accented characters into their base form and diacritical marks
.replace(/[\u0300-\u036f]/g, '') // remove all the accents
.trim()
.toLowerCase()
.replace(/\./g, '-') // some titles (configuration) contain keypath, so replace dots with hyphens
.replace(/[^a-z0-9 -]/g, '') // remove non-alphanumeric characters
.replace(/\s+/g, '-') // replace spaces with hyphens
.replace(/-+/g, '-') // remove consecutive hyphens
}
export const h = (order: 1 | 2 | 3 | 4 | 5 | 6): ElementType<TitleProps> => {