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

Add line numbers to prismjs plugin #5821

Merged

Conversation

phacks
Copy link
Contributor

@phacks phacks commented Jun 9, 2018

Hi! First time contributor, please feel free to tell me how I can improve the PR 😊

This PR adds the ability to show line numbers for code blocs using the PrismJS line number plugin.

See example:

image

This relates to the issue #5775.

Oops, just realized that it didn’t work well with highlighted lines, I’ll try to take another look at this soon! Edit: fixed! 🎉

image

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch 2 times, most recently from 4baa2ef to 905f7bc Compare June 9, 2018 18:16
@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit ba1aa0f0a2333902fbec38b071df5e85145ba5f8

https://deploy-preview-5821--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 9, 2018

Deploy preview for using-drupal ready!

Built with commit ece4d0d

https://deploy-preview-5821--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 9, 2018

Deploy preview for gatsbygram ready!

Built with commit ece4d0d

https://deploy-preview-5821--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit ba1aa0f0a2333902fbec38b071df5e85145ba5f8

https://deploy-preview-5821--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit 4baa2ef621a6e665f33747d18c2077d7c966dc80

https://deploy-preview-5821--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit 4baa2ef621a6e665f33747d18c2077d7c966dc80

https://deploy-preview-5821--gatsbygram.netlify.com

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch 2 times, most recently from 8a780a5 to 92d361c Compare June 9, 2018 20:43
@jasperjn
Copy link

jasperjn commented Jun 11, 2018

@phacks I created a PR phacks#1 remove build version file from the source control. Thank you.

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

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

Oh good stuff @phacks, thanks. I tried this on the using-remark example and the code blocks were overlapping the line numbers.

screen shot 2018-06-12 at 13 22 55

Is that something that can be fixed?

@m-allanson
Copy link
Contributor

m-allanson commented Jun 12, 2018

Another thought.. This PR enables or disables line numbering for a whole site. It might be useful to specify line number for individual blocks, and also the starting line number for a block. I'm not sure what the best way to do that, maybe similarly to the line highlighting syntax?

Number lines, starting from 1:

 ```js{6-8}{numberLines: true}

Number lines, starting from 5:

 ```js{6-8}{numberLines: 5}

Thoughts?

@phacks
Copy link
Contributor Author

phacks commented Jun 12, 2018

Hi @m-allanson! Thanks for the feedback. I’ll be looking into the layout issues and the possible enhancements, hopefully in the next few days 😊

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch from 53d8452 to a2a308e Compare June 14, 2018 12:31
@phacks
Copy link
Contributor Author

phacks commented Jun 14, 2018

I fixed the issue on using-remark and added the featured your suggested @m-allanson !

The issue was caused by this padding overwriting the prism-line-numbers.css stylesheet :

a2a308e#diff-2e101cb7175492ace9066869ab398490L135

Removing it didn’t impact the code block style, so I went with it — what do you think?

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch from a2a308e to fe303b4 Compare June 14, 2018 14:57
@phacks
Copy link
Contributor Author

phacks commented Jun 14, 2018

It looks like recent Travis builds are failing with an obscure versioning error:

image

Would you have an idea on how to fix it?

@pieh
Copy link
Contributor

pieh commented Jun 14, 2018

@phacks this is something I introduced and need to fix! Sorry for disturbance

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch from fe303b4 to cea7660 Compare June 16, 2018 21:05
@phacks
Copy link
Contributor Author

phacks commented Jun 16, 2018

@pieh It’s fixed! Many thanks 😊

@phacks
Copy link
Contributor Author

phacks commented Jun 17, 2018

Just tried to rebase to master and it broke the code blocks layout again… Back to the drawing board!

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch from cea7660 to 44d8463 Compare June 17, 2018 21:40
@phacks
Copy link
Contributor Author

phacks commented Jun 17, 2018

…aaand it’s fixed again!

image

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch 2 times, most recently from 1c905f5 to 1512bbd Compare June 20, 2018 09:11
@m-allanson m-allanson dismissed their stale review June 27, 2018 13:24

changes made

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch from ae322e4 to beff9ea Compare July 17, 2018 12:50
@phacks
Copy link
Contributor Author

phacks commented Jul 17, 2018

@m-allanson Fixed, thanks! I think I made a mistake somewhere while migrating the branch to v2 😅

@phacks
Copy link
Contributor Author

phacks commented Jul 24, 2018

@m-allanson @KyleAMathews Hi! Small reminder that I updated my PR and it should be ready to go! Thanks 😊

@phacks
Copy link
Contributor Author

phacks commented Jul 31, 2018

@m-allanson @KyleAMathews Hi! This PR should be ready for you to review and merge, many thanks!

@m-allanson
Copy link
Contributor

Thanks for the reminders @phacks, sorry you had to wait so long on another review for this.

I ran through another check, and generally things look good 👍 However, I noticed one issue that will need fixing. It seems that this change adds extra padding around all code blocks, which it shouldn't do. Here's a couple of screenshots with this PR on the left, and the currently live example site on the right:

screen shot 2018-08-01 at 10 50 33

screen shot 2018-08-01 at 10 51 10

It seems there's extra padding on all sides of the code blocks. Could you fix that up to match the padding on the live example site? Apologies in advance if this is an annoying CSS specificity thing!

Hopefully fixing this will remove some of that large gap to the left of the line-numbers which should look a bit neater too. Please drop any questions here if you have them, I'll endeavor to get to them more quickly this time 😅

@phacks
Copy link
Contributor Author

phacks commented Aug 1, 2018

@m-allanson @KyleAMathews How did I miss that 😅Should be better now, as you can see:

image
image

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 1, 2018

Deploy preview for using-postcss-sass failed.

Built with commit ece4d0d

https://app.netlify.com/sites/using-postcss-sass/deploys/5b72ce87c6aed62d422b61f3

@phacks phacks force-pushed the topics/5775-add-line-numbers-to-prism-plugin branch from 53eae6e to a5cc869 Compare August 1, 2018 15:44
@KyleAMathews
Copy link
Contributor

Deploy preview for gatsbyjs failed.

Built with commit 53eae6e1667ed48cdb5160dce6520f5a491b24f1

https://app.netlify.com/sites/gatsbyjs/deploys/5b61d3eac9659221ab5dfd3e

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 1, 2018

Deploy preview for gatsbyjs failed.

Built with commit ece4d0d

https://app.netlify.com/sites/gatsbyjs/deploys/5b72ce86c6aed62d422b61e7

@phacks
Copy link
Contributor Author

phacks commented Aug 8, 2018

@m-allanson @KyleAMathews Sorry if I come off as a little bit pushy — do you think you can have another look (and hopefully the last one!) at this PR, now that I fixed the CSS padding problem? Many thanks! 😊

@m-allanson
Copy link
Contributor

Hey @phacks, don't worry that's not pushy, it's good to get reminders sometimes! I want to get back to this as soon as I can, but it's looking like that'll be early next week. Sorry for the delay and thanks again for your patience.

* master: (597 commits)
  Add a site(https://mojaave.com) to showcase list (gatsbyjs#7275)
  feat: create a doc for open source pair programming sessions (gatsbyjs#7266)
  [docs] Add video lesson to the StaticQuery docs (gatsbyjs#7249)
  [v2] docs - update page query docs (gatsbyjs#7285)
  [v2] docs "Styling" overview (gatsbyjs#7288)
  Remove delay (gatsbyjs#7273)
  add site (gatsbyjs#7291)
  Adding new site to the showcase. (gatsbyjs#7281)
  chore(release): Publish
  initial webpack externals support (gatsbyjs#7245)
  add missing package dependencies (gatsbyjs#7259)
  add: custom configuration overview
  (gatsbyjs#7231): tutorial part four updates (gatsbyjs#7240)
  [www] Fix showcase search, checkbox styles (gatsbyjs#7014)
  (gatsbyjs#6584): Restructure plugin overview and plugin authoring pages (gatsbyjs#7229)
  Use Hubspot form for email subscription (gatsbyjs#7233)
  Adding bootstrap CV starter (gatsbyjs#7207)
  Stub Articles and new names (gatsbyjs#7200)
  Improve readability of verbose logging code in wordpress source plugin (gatsbyjs#7146)
  Update hash link to scroll to right section of page (gatsbyjs#7161)
  ...
@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 14, 2018

Deploy preview for using-contentful failed.

Built with commit ece4d0d

https://app.netlify.com/sites/using-contentful/deploys/5b72ce89c6aed62d422b6202

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

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

I think this looks good to go 🎉 thanks @phacks!

I merged the latest changes from master in, broke something, fixed it, added a few more tests and an extra example. Can you check my changes look good to you? If so we can get this merged in :)

@phacks
Copy link
Contributor Author

phacks commented Aug 14, 2018

@m-allanson Awesome, thanks! Looked through your commits and they are fine by me. You can go ahead and merge the PR ☺️

@m-allanson m-allanson merged commit 1e9a8e5 into gatsbyjs:master Aug 14, 2018
@gatsbot
Copy link

gatsbot bot commented Aug 14, 2018

Holy buckets, @phacks — 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. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. 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!

@phacks phacks deleted the topics/5775-add-line-numbers-to-prism-plugin branch August 14, 2018 16:24
@m-allanson
Copy link
Contributor

This has been published as gatsby-remark-prismjs@3.0.0-beta.6

porfirioribeiro pushed a commit to porfirioribeiro/gatsby that referenced this pull request Aug 22, 2018
* Add line numbers to prismjs plugin

* Fix line numbers with line highlighting layout problems

* Scope line numbering by code block, add start index

* Fix line numbering problem in using-remark example

* Add <gatsby-remark-prismjs>/add-line-numbers.js to gitignore

* Fix oversized padding around code blocks

* Run missed tests and add a few more

* Make it easier to read generated code string

* Use plain old string concatenation instead

* Add one more snapshot test

* Add another example

* Skip formatting for this block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants