mirror of https://github.com/ethereum/go-ethereum
* expand parseHeadingId Will produce a kebab-case heading ID from string if none explicitly declared in the markdown. Always returns an object with the children, title and headingId. * remove redundant code from MDComponents.tsx parseHeadingIds now always returns an object with an ID, removing need for conditionals here * Use Box instead of flex Stack for MDX content Allows stacked vertical margins to properly collapse into each other * fix: h2 top margin to 3rem on mobile * remove unneeded line * extract and rename getKebabCaseFromName util fn * Update src/pages/[...slug].tsx * Update src/utils/parseHeadingId.ts Co-authored-by: Corwin Smith <cssmittys@gmail.com> * move constant inside function make variable name all caps as a string constant * clean up utils/index.ts to abc order Co-authored-by: Corwin Smith <cssmittys@gmail.com>pull/26459/head^2
parent
332e972397
commit
56b9963afd
@ -0,0 +1,7 @@ |
||||
export const getKebabCaseFromName = (name: string): string => |
||||
name |
||||
.replace(/[#]/g, '') |
||||
.trim() |
||||
.toLowerCase() |
||||
.replace(/ /g, '-') |
||||
.replace(/[^a-z0-9-]/g, ''); |
@ -1,18 +1,22 @@ |
||||
const check = '{#'; |
||||
import { getKebabCaseFromName } from './'; |
||||
|
||||
export const parseHeadingId = (children: string[]) => { |
||||
if (children[children.length - 1].includes(check)) { |
||||
const temp = children[children.length - 1].split(check); |
||||
const headingId = temp[temp.length - 1].split('}')[0]; |
||||
|
||||
children[children.length - 1] = temp[0]; |
||||
|
||||
const CHECK = '{#'; |
||||
const lastChild = children[children.length - 1]; |
||||
const split = lastChild.split(CHECK); |
||||
if (lastChild.includes(CHECK)) { |
||||
const headingId = split[split.length - 1].split('}')[0]; |
||||
const newChildren = [...children]; |
||||
newChildren[newChildren.length - 1] = split[0]; |
||||
return { |
||||
children, |
||||
title: temp[0].replaceAll('#', ''), |
||||
children: newChildren, |
||||
title: split[0].replaceAll('#', ''), |
||||
headingId |
||||
}; |
||||
} |
||||
|
||||
return null; |
||||
return { |
||||
children, |
||||
title: split[0].replaceAll('#', ''), |
||||
headingId: getKebabCaseFromName(split[0]) |
||||
}; |
||||
}; |
||||
|
Loading…
Reference in new issue