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

feat: mdx TOC #883

Merged
merged 26 commits into from
Jun 3, 2024
Merged

feat: mdx TOC #883

merged 26 commits into from
Jun 3, 2024

Conversation

kellyjosephprice
Copy link
Collaborator

@kellyjosephprice kellyjosephprice commented May 23, 2024

PR App Fix RM-9179

🧰 Changes

TOC!!1!1

The old TOC worked by parsing the mdast for heading via mdast-util-toc. This produces an mdast suitable for rendering via the TableOfContents component. The package remark-slug appears to be abandoned, and the mdx maintainers recommend using rehype-slug and rehype-extract-oc. rehype-extract-toc generates a POJO that represent the TOC, and it doesn't appear to have any functions for parsing component imports. So, I've implemented a plugin that parses the main doc and it's components hast's during the compile step. Then it can be rendered in the TableOfContents during the run step. This changes the return signatures to be an object instead of a single component, to prevent requiring 2 separate compile and run steps when rendering.

Other notable changes:

  • Refactored run, compile, mdx, astProcessor into their own files under ./lib
  • Deleted the Style component.
  • Deleted some tests (maybe not a great idea?).
  • Added execute test helper.

🧬 QA & Testing

@kellyjosephprice kellyjosephprice changed the base branch from next to beta May 23, 2024 19:48
@kellyjosephprice
Copy link
Collaborator Author

The failing snapshot is the flaky embed one

@kellyjosephprice kellyjosephprice marked this pull request as ready for review May 30, 2024 20:33
@kellyjosephprice
Copy link
Collaborator Author

@Rafe this is really ready for review

.env Outdated Show resolved Hide resolved
lib/ast-processor.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@rafegoldberg rafegoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a couple more suggestions, but this worked great when I tested locally! 🤘 And like I said, I appreciate the code cleanup herein!

Comment on lines +25 to +29
```
###A Valid Heading

Lorem ipsum dolor etc.
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not to be picky since I know this isn't technically within the scope of this PR, but I did notice that this compact header notation isn't working with the new MDX processor!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

components/Heading/index.tsx Outdated Show resolved Hide resolved
</div>
<a
key={`heading-anchor-icon-${id}`}
aria-label={`Skip link to ${children[1]}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this children[1] logic still makes sense now that we're getting rid of the showAnchorIcons option?1

Maybe it should just be:

aria-label={`Skip link to ${children}`}

Footnotes

  1. side note: why are we getting rid of this? is it just not used anywhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see it used anywhere, so I didn't bother porting it?

kellyjosephprice and others added 3 commits June 3, 2024 10:01
Co-authored-by: Rafe Goldberg <rafegoldberg@gmail.com>
@kellyjosephprice kellyjosephprice merged commit ef8f9a1 into beta Jun 3, 2024
9 of 11 checks passed
@kellyjosephprice kellyjosephprice deleted the beta-toc branch June 3, 2024 17:23
rafegoldberg pushed a commit that referenced this pull request Jun 3, 2024
## Version 6.75.0-beta.48

### ✨ New & Improved

* mdx TOC ([#883](#883)) ([ef8f9a1](ef8f9a1))

<!--SKIP CI-->
@rafegoldberg
Copy link
Contributor

This PR was released!

🚀 Changes included in v6.75.0-beta.48

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

Successfully merging this pull request may close these issues.

None yet

2 participants