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(gatsby-remark-autolink-headers): Support {#custom-id} header syntax #14253

Merged
merged 6 commits into from
Jun 14, 2019
Merged

Conversation

yunabe
Copy link
Contributor

@yunabe yunabe commented May 22, 2019

Description

Support custom heading ID syntax in gatsby-remark-autolink-headers (disabled by default)

### My Great Heading {#custom-id}

https://www.markdownguide.org/extended-syntax/#heading-ids

DSchau
DSchau previously requested changes May 22, 2019
Copy link
Contributor

@DSchau DSchau left a comment

Choose a reason for hiding this comment

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

Great! I know (or thought I know) that reactjs.org uses an approach kind of like this--it'd be nice to bake this into the plugin so everyone can get this benefit, so thanks for taking the initiative here!

Left a few comments/requests 👇

visit(transformed, `heading`, node => {
expect(node.data.id).toBeDefined()

expect(node).toMatchSnapshot()
Copy link
Contributor

Choose a reason for hiding this comment

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

Sort of a nit: but generally I'd argue we way overuse snapshots and they make future failures more confusing than they need to be.

Could you rather test for a specific id, e.g. something like

const customId = `custom-id`

const markdownAST = remark.parse(`
# Heading With a Custom Id {#${customId}}
`)

// later

visit(transformed, `heading`, node => {
  expect(node.data.id).toBe(customId)
})

Obviously you can scale this however you'd like if there's value in testing for multiple instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I rewrote this test without using snapshots. Does it look better? If you like this, I will rewrite other tests with this style in another PR.

@DSchau DSchau self-assigned this May 23, 2019
@DSchau DSchau added the status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response label May 28, 2019
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

I have added a question as @DSchau is busy spreading the word about gatsby on a conference. This looks pretty good!

Could you also add 3 tests? 1 to check we still generate an id when no {#id} is specified, a second one to check that we don't convert headings with only the {#id} as text and a last one to test that we don't use the custom id from this node {#id} some text

@yunabe yunabe requested a review from a team as a code owner June 13, 2019 14:32
@yunabe
Copy link
Contributor Author

yunabe commented Jun 13, 2019

Added additional tests. Could you take another look?

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Well done! 👏 Thanks for addressing all comments. Let's ship this! 🚀

@wardpeet wardpeet dismissed DSchau’s stale review June 14, 2019 07:13

all taken care of

@wardpeet wardpeet changed the title Support {#custom-id} header syntax in gatsby-remark-autolink-headers feat(gatsby-remark-autolink-headers): Support {#custom-id} header syntax Jun 14, 2019
@wardpeet wardpeet merged commit 63dd87b into gatsbyjs:master Jun 14, 2019
@gatsbot
Copy link

gatsbot bot commented Jun 14, 2019

Holy buckets, @yunabe — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. We’ve got Gatsby t-shirts, stickers, hats, scrunchies, and much more. (You can also unlock even more free swag with 5 contributions — wink wink nudge nudge.) See gatsby.dev/swag for details.
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@wardpeet
Copy link
Contributor

published in gatsby-remark-autolink-headers@2.0.17 🎉

@yunabe
Copy link
Contributor Author

yunabe commented Jun 14, 2019

Thank you for the reviewing, Ward.
Also, it's great to see my PR was released so quickly. Amazing😄

mxxk pushed a commit to mxxk/gatsby that referenced this pull request Jun 21, 2019
…tax (gatsbyjs#14253)

- add enableCustomId option
- enable usage of custom-id ``{#custom-id}` when enableCustomId  is set to true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants