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

refactor(markdown): removed rehype-slug in favor of our own implementation #3234

Merged
merged 9 commits into from Apr 30, 2022

Conversation

JuanM04
Copy link
Contributor

@JuanM04 JuanM04 commented Apr 28, 2022

Changes

While reviewing #3044, I've noticed that there is a function (rehypeCollectHeaders) which is being used to generate slugs no matter what plugins the user specified. So, I've removed rehype-slug because it was doing the exact same thing (it even uses the same slugger!).

Sidenote: I've moved some types around, so headers are typed instead of any[]

Testing

It's already being tested

Docs

TDB

@changeset-bot
Copy link

changeset-bot bot commented Apr 28, 2022

🦋 Changeset detected

Latest commit: 73e1610

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@astrojs/markdown-remark Patch
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) feat: markdown Related to Markdown (scope) labels Apr 28, 2022
@JuanM04 JuanM04 changed the title refactor: removed rehype-slug in favor of our own implementation refactor(markdown): removed rehype-slug in favor of our own implementation Apr 28, 2022

function rehypeCollectHeaders() {
return function (tree: any) {
const rehypeCollectHeaders: RehypePlugin<[]> = () => {
Copy link
Member

Choose a reason for hiding this comment

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

style nit: we usually avoid const X = () => {} in this code base, in favor of function X() {}.

Unless I'm missing something, you should be able to get the same type info like this:

function rehypeCollectHeaders(): RehypePlugin<[]> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated that!

Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM with 1 small style comment! Merge when ready

@github-actions github-actions bot added pkg: example Related to an example package (scope) test labels Apr 28, 2022
@FredKSchott
Copy link
Member

Feel free to merge if you can confirm that this PR didn't introduce this issue: withastro/docs#404 (comment)

@JuanM04
Copy link
Contributor Author

JuanM04 commented Apr 29, 2022

@FredKSchott ok, so I've added some notes about how it currently works (with or without this PR) in the documentation:

Astro will add autogenerated ids to all headings in Markdown files automatically using github-slugger — if a custom id is specified, it won't be overriden. These ids will be added after all the other plugins are executed, so if you have a plugin like rehype-toc that needs ids, you should add your own slugging plugin (like rehype-slug).

Copy link
Member

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

LGTM

@JuanM04 JuanM04 merged commit de123b2 into main Apr 30, 2022
@JuanM04 JuanM04 deleted the juanm04/markdown-slug branch April 30, 2022 00:07
@github-actions github-actions bot mentioned this pull request Apr 30, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
…ntation (withastro#3234)

* Moved types arround

* Removed `rehype-slug` in favor of our own implementation

* Changeset

* Removed rehype-slug from examples

* Remove rehype-slug from tests

* Updated reference

* rehypeCollectHeaders is a function again

* Reverted rehype-slug removes

* Re-added rehype-slug to reference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants