Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS MDX: rehype-toc does not work as expected #12

Open
Samuele1818 opened this issue Aug 8, 2023 · 0 comments
Open

NextJS MDX: rehype-toc does not work as expected #12

Samuele1818 opened this issue Aug 8, 2023 · 0 comments

Comments

@Samuele1818
Copy link

I'm creating a blog using NextJs13 and MDX, I have added a table of contents to my pages using rehype-toc.

I want the table (so element) to be outside the article element, to do this I tried to use the position attribute in the plugin config, but it not worked as expected.

next.config.mjs

const withMDX = createMDX({
   extension: /\.mdx?$/,
   options: {
        ...
        [rehypeToc, {
            headings: ["h1"],
            // I suppose that TOC will be inserted after the article element
            // (so to be a child of the `<main>` element)
            position: "afterend"
            cssClasses: {
                toc: "toc not-prose",
                link: "toc-link"
            },
        }]
   }},
})

page.tsx

const Index: NextPage = ({ params }: any) => {
const { post } = params

const PostFile = dynamic(() => import(`../posts/${post}.mdx`).
   catch(() => notFound())
)

 return (
   <main>
     <article className='prose prose-slate lg:prose-xl'>
       <PostFile />
     </article>
   </main>
  )
}

If you need more information code is public on my GitHub (blog code is located in /app/blog).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant