Skip to content

How can I generate a sidebar table of contents (TOC) based on my file? #1373

Answered by Timeless0911
huyixi asked this question in Q&A
Discussion options

You must be logged in to vote
  • mdx-rs:
    const { compile } = require('@rspress/mdx-rs');
    const { toc, links, title, code } = await compile({
    value: preprocessedContent,
    filepath,
    root: docDirectory,
    development: process.env.NODE_ENV !== 'production',
    });
  • mdx-js:
    export const remarkPluginToc: Plugin<[], Root> = function (this: Processor) {
    const data = this.data() as {
    pageMeta: PageMeta;
    };
    return (tree: Root) => {
    const { toc, title } = parseToc(tree);
    data.pageMeta.toc = toc;

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Timeless0911
Comment options

@huyixi
Comment options

Answer selected by huyixi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants