Install
npm i remark-heading-anchor
Examples
import { remark } from "remark"
import remarkHeadingAnchor from "remark-heading-anchor"
import ReactMarkdown from 'react-markdown'
async function main() {
const file = await remark()
.use(remarkHeadingAnchor, {
idPrefix: 'heading-'
})
.process('# title')
console.log(file, 'file')
}
main()
const HeadingComponent = ({ index, children }) => {
return React.createElement(
`h1`,
{
id: `heading-${index}`,
},
children
);
};
const App = () => {
return (
<ReactMarkdown
components={{
h1: HeadingComponent,
}}
includeElementIndex // Use with idPrefix
>
{/* ...content */}
</ReactMarkdown>
)
}