-
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
fix(gatsby-remark-prismjs): Use gatsby-highlight class to calculate line numbers #23031
fix(gatsby-remark-prismjs): Use gatsby-highlight class to calculate line numbers #23031
Conversation
This looks nice! Can we add some test cases to https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-prismjs/src/__tests__/index.js that would use both line numbers and some additional directives and make sure there are no empty lines produced? |
Sure I'll work on a few test cases. |
@pieh I've pushed a snapshot + unit test for the new functionality, check them out and let me know if that's what you're looking for. (They pass for me on my local environment) If they look good, I can create a few larger tests with multiple directives. |
Ah, I missed the fact how exactly line numbers are implemented - the empty For now I have no further actionable comments for you, and this is waiting on me |
…n pretty confusing html
@miles-crighton Take a look at miles-crighton#1 (PR against this PR :) ) as attempt at making nicer assertions |
test: explicitely count line number rows instead of trying to match on pretty confusing html
That looks great - much more explicit and understandable :) Where do you want to go from here? |
I think we are good for now. Given that line numbering and using directives was completely broken and this fixes this (at least for cases we tested) I'd say this is good to go in. If there will be further problems discovered we can iterate (and we have structure/assertion for line numbers tests so we can add problematic cases to tests as we discover them to make sure we don't regress in the future). One thing that I'll do right now is to update branch to sync with master (we very recently upgraded prettier, so need to make sure that PR branch is on the same version of prettier as master) |
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 great, let's get this in! Thanks @miles-crighton!
Holy buckets, @miles-crighton — 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! |
Pleasure working with you @pieh :)! |
Description
The output of the line highlighting parser is now passed to the line number generator to calculate the required line number spans to be created. Before, these two procedures were being run independently from one another. This change results in the line number generation now being dependent on the line highlighting parser apposed to the raw code-block markdown.
The line number generator now uses the newline (
\n
) delimiter in combination with matches of the HTML classgatsby-highlight-code-line
to calculate the required line number count.This solution was generated with the help of @pieh's suggestion on #22962.
Documentation
Shouldn't affect documentation as this attempts to fix a bug preventing expected behaviour.
Related Issues
Fixes #22962