supMDX/core/components/heading.tsx
2023-02-16 09:54:31 +09:00

12 lines
364 B
TypeScript

import React from 'react';
const hx = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
export const anchoredHx = Object.fromEntries(hx.map(H => [
H,
({children, id, ...props}: React.ComponentProps<(typeof hx)[number]>) => (
<H {...{id, ...props}}>
{id && <a className="anchor" href={'#'+encodeURIComponent(id)} />}
{children}
</H>
),
]));