
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
@opensourceframework/next-mdx-toc
Advanced tools
Add table of contents to MDX.
npm i --save next-mdx-toc remark-slug remark-autolink-headings
getMdxNode:const doc = await getMdxNode("doc", context, {
mdxOptions: {
remarkPlugins: [
require("remark-slug"),
require("remark-autolink-headings"),
],
},
})
getTableOfContents(node: MdxNode): TableOfContents:const toc = await getTableOfContents(doc)
import * as React from "react"
import { getMdxNode } from "next-mdx/server"
import { getTableOfContents } from "next-mdx-toc"
export default function Page({ doc, tableOfContents }) {}
export async function getStaticProps(context) {
const doc = await getMdxNode("doc", context, {
mdxOptions: {
remarkPlugins: [
require("remark-slug"),
require("remark-autolink-headings"),
],
},
})
return {
props: {
doc,
tableOfContents: await getTableOfContents(doc),
},
}
}
To render the table of contents, use a recursive component type:
import { TableOfContents } from "next-mdx-toc"
function Toc({ tree }: { tree: TableOfContents }) {
return tree?.items.length ? (
<ul>
{tree.items.map((item) => {
return (
<li key={item.title}>
<a href={item.url}>{item.title}</a>
{item.items?.length ? <Toc tree={item} /> : null}
</li>
)
})}
</ul>
) : null
}
<Toc tree={tableOfContents} />
If you want to add the table of contents to your MdxNode, you can do so as follows:
import { TableOfContents } from "next-mdx-toc"
import { MdxNode } from "next-mdx/server"
interface Doc extends MdxNode {
toc: TableOfContents
}
Licensed under the MIT license.
FAQs
Add table of contents to MDX
We found that @opensourceframework/next-mdx-toc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.