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

How should return Jsx.Element for customizeTOC ? #11

Open
jaycethanks opened this issue Jul 27, 2023 · 0 comments
Open

How should return Jsx.Element for customizeTOC ? #11

jaycethanks opened this issue Jul 27, 2023 · 0 comments

Comments

@jaycethanks
Copy link

Thanks for this awesome plugin, and I'm trying to wrap a <motion.div> for created TOC, but for some reason, It seems does not support the feature. Here is my related code:

.....
interface NodeTree {
  type: string;
  properties: {
    [key: string]: any;
  };
  children: (NodeTree | string)[];
}
function renderNodeTree(nodeTree: NodeTree): JSX.Element {
  const { type, properties, children } = nodeTree;

  const childElements = (children || []).map((child) => {
    if (typeof child === 'string') {
      return child;
    } else {
      return renderNodeTree(child);
    }
  });

  return React.createElement(type, properties, ...childElements);
}

function customizeTOC(toc:NodeTree){
  const tocJsx = renderNodeTree(toc)
  // return <motion.div>{tocJsx}</motion.div>
  return "Hello"
  // console.log('[toc]: ',tocJsx)
}
.....
      <ReactMarkdown
        className="markdown-body"
        children={contentStr || ''}
        rehypePlugins={[rehypeRaw,[rehypeToc,{customizeTOC,cssClasses:{toc:tocStyle['markdown-toc']}}]]}
        remarkPlugins={[remarkEmoji,remarkGfm,remarkMermaidjs]}
.....

Thanks again!

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