-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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-transform-remark): populate id to headings from markdownAST #23546
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few small comments to address
additionally - but this might not be straight forward to do - would it be possible to add test case - following
gatsby/packages/gatsby-transformer-remark/src/__tests__/extend-node.js
Lines 1243 to 1267 in e1ef491
bootstrapTest( | |
`returns value`, | |
` | |
# first title | |
## second title | |
`, | |
`headings { | |
value | |
depth | |
}`, | |
node => { | |
expect(node).toMatchSnapshot() | |
expect(node.headings).toEqual([ | |
{ | |
value: `first title`, | |
depth: 1, | |
}, | |
{ | |
value: `second title`, | |
depth: 2, | |
}, | |
]) | |
} | |
) |
id
s?
@pieh , how do you run test locally?
and
|
You would need to run |
packages/gatsby-transformer-remark/src/__tests__/extend-node.js
Outdated
Show resolved
Hide resolved
Hi @pieh , |
Figured out how to setup test to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome - thanks!
Holy buckets, @bongnv — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
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! |
should the |
Description
Currently, in order to generate table of contents, we can use
tableOfContents
in gatsby-transform-remark together gatsby-remark-autolink-headers. However,tableOfContents
is kind of static and it's hard to add more effects.Using
headings
instead doesn't return enough information (id
oranchor
) in order to link to heading.The MR will populate
id
fromdata.id
orid
indata.HTMLAttributes
inmarkdownAST
in.With schema
headings
should be able to provide enough information to render a custom TOC.Documentation
id
needs to be populated in order to use. It works best with gatsby-remark-autolink-headers.If
id
is available, it is an empty string by default.Use
To query headings.
Related Issues