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

TOC shows comments in headings #10018

Closed
6 of 7 tasks
plocket opened this issue Apr 4, 2024 · 2 comments
Closed
6 of 7 tasks

TOC shows comments in headings #10018

plocket opened this issue Apr 4, 2024 · 2 comments
Labels
closed: duplicate This issue or pull request already exists in another issue or pull request

Comments

@plocket
Copy link

plocket commented Apr 4, 2024

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

The table of contents menu shows the comments in the heading, well as the text of the other nodes.

There is probably an issue for this already, but I couldn't find it.

Reproducible demo

https://codesandbox.io/p/devbox/intelligent-franklin-s3vldx

Steps to reproduce

  1. Make a heading
  2. Add either a MDX comment or an html comment
  3. See that the comments are correctly invisible in the heading
  4. See that the text is visible in the table of contents

Expected behavior

I thought the text of the comment that I put in the heading would be invisible in the table of contents.

Actual behavior

The text of the comments was visible in the table of contents.

Your environment

Self-service

  • I'd be willing to fix this bug myself.
@plocket plocket added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Apr 4, 2024
@Abdullah-03
Copy link
Contributor

TOC in docusaurus-mdx-loader currently does not parse JSX. Not just comments but any expression is simply just converted to string i.e.

{5 + 5}

becomes "5 + 5".

In the code a comment actually states this as a todo

// TODO This is really a workaround, and not super reliable
// For now we only support serializing tagName, className and content
// Can we implement the TOC with real JSX nodes instead of html strings later?

I tried implementing it but wasn't able to without making the code insecure (eval). If a maintainer can point out how that is achieved for headings within the document I could work towards porting it for the TOC. I wasn't able to find that implementation by myself.

@Josh-Cena
Copy link
Collaborator

Calling it a duplicate of #9772

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2024
@Josh-Cena Josh-Cena added closed: duplicate This issue or pull request already exists in another issue or pull request and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: duplicate This issue or pull request already exists in another issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants