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-embed-snippet): Add the ability to embed named snippets #24512

Merged
merged 11 commits into from
Jun 24, 2020

Conversation

BobWall23
Copy link
Contributor

Description

Adds a feature to the gatsby-remark-embed-snippet plugin that makes it possible for someone to add inline comments to a source file to delineate one or more named snippets, and to embed snippets by name.

Documentation

The new feature is documented in the README.md for the gatsby-remark-embed-snippet plugin.

Related Issues

Makes it possible for someone to add inline comments to a source file
delineating one or more named snippets, and to embed snippets by name.
@BobWall23 BobWall23 requested review from a team as code owners May 26, 2020 19:31
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 26, 2020
@BobWall23 BobWall23 changed the title Add the ability to embed named snippets feat(gatsby-remark-embed-snippet) Add the ability to embed named snippets May 26, 2020
@BobWall23 BobWall23 changed the title feat(gatsby-remark-embed-snippet) Add the ability to embed named snippets feat(gatsby-remark-embed-snippet): Add the ability to embed named snippets May 26, 2020
@vladar vladar added status: needs core review Currently awaiting review from Core team member topic: remark/mdx Related to Markdown, remark & MDX ecosystem status: needs dx review and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels May 27, 2020
@pieh
Copy link
Contributor

pieh commented May 27, 2020

This looks awesome!

I do however would want to discuss a bit way in which we specify snippet names to be used. Doing embed:file#SNsnippetName will work but I do wonder if we should try to take hint out of gatsby-remark-prismjs book and instead have something like embed:file{ snippet: "snippetName" } - for users not familiar with #SN<snippetName> syntax I think this will be easier to understand (and also give us room to implement other options/attributes in the future without overloading # (which can be reserved for line numbers)

@pieh
Copy link
Contributor

pieh commented May 27, 2020

Another thing is about marking snippets - using them with comments is fine, i just think we should use conventions we already have for line highlighting - so (potentially) // START SNIPPET bar -> // start-snippet{bar} - this is just so API is consistent and parts of it feel like they go well together.

Let me know what do you think

@BobWall23
Copy link
Contributor Author

Thanks for the suggestions - I think it is good to make this fit in better. I didn't look far enough outside this plugin to see how some of the others worked. I will update to match the prismjs syntax better, using the syntax you suggested.

@pieh
Copy link
Contributor

pieh commented May 27, 2020

Those were just examples - we might end up with them, but I'd like to encourage you to take a peek into what syntax conventions are used currently and maybe see if you can come up with better ones. You could take a look in both in gatsby-remark-embed-snippet and gatsby-remark-prismjs (because those 2 are pretty close together and both are used for similar results - showing some code blocks).

@BobWall23
Copy link
Contributor Author

Those suggestions do seem to be in line with the syntax used in the prismjs plugin. The only option syntax in the embed-snippet plugin is the #L parsing.

I think it is pretty unfortunate that prismjs used {optionName : value} instead of {"optionName" : value}, to facilitate standard JSON parsing. I can continue with similar syntax (no double quotes around the option names) or use standard JSON conventions. I prefer the latter, in spite of the slight mismatch in syntax.

Based on review feedback, changed from `#SN<snippetName>` to
`{snippet: "snippetName"}`. Also, marking the named snippet in
the referenced file uses `start-snippet{snippetName}` and
`end-snippet{snippetName}` instead of `BEGIN SNIPPET snippetName`
and `END SNIPPET snippetName`.

This syntax is used by prismjs for other option selections and
inline comments.
@BobWall23
Copy link
Contributor Author

I went with a change that doesn't require double quotes around the snippet keyword - it would be a trivial change plus update to the docs to switch over to valid JSON format. I think that would be more robust if new options were added.

I wonder if I blew the commits by not using the conventional commit standard? I was thinking I just needed to worry about the pull request, not the individual commits to my fork. Hopefully that is correct.

@pieh
Copy link
Contributor

pieh commented Jun 1, 2020

I wonder if I blew the commits by not using the conventional commit standard? I was thinking I just needed to worry about the pull request, not the individual commits to my fork. Hopefully that is correct.

This is correct - we are "squashing and merging", so single commit will end up in master - and if there is more than 1 commit in PR - PR title is used

pieh
pieh previously requested changes Jun 1, 2020
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

minor inconsistencies to fix up and one extra question

packages/gatsby-remark-embed-snippet/README.md Outdated Show resolved Hide resolved
packages/gatsby-remark-embed-snippet/README.md Outdated Show resolved Hide resolved
packages/gatsby-remark-embed-snippet/src/index.js Outdated Show resolved Hide resolved
BobWall23 and others added 2 commits June 1, 2020 10:49
Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
@BobWall23
Copy link
Contributor Author

I notice that the lint check is failing due to an extra space in docs/blog/2020-05-22-happy-fifth-bday-gatsby/index.md. If I fix that, the lint passes - should I commit that change into this PR?

@BobWall23 BobWall23 requested a review from a team as a code owner June 1, 2020 17:09
@pieh
Copy link
Contributor

pieh commented Jun 1, 2020

I notice that the lint check is failing due to an extra space in docs/blog/2020-05-22-happy-fifth-bday-gatsby/index.md. If I fix that, the lint passes - should I commit that change into this PR?

You can merge master branch of gatsbyjs/gatsby into your branch and push it (lint was fixed in master already).

Assuming origin = gatsbyjs/gatsby:

git fetch origin master
git merge origin/master
git push <your_fork> packages/add-named-snippets

should fix lint problems

Alternatively - you can go ahead and fix the lint separately in your branch - because it was fixed already in master - this change should not show in PR view

Based on PR review, changed code to find the start and end of the
snippet to use regular expressions. Nicer, easier to understand.
@pieh
Copy link
Contributor

pieh commented Jun 2, 2020

All right, code has sign off from me - it looks great and tests are great! Now just need to review for docs changes

@pieh pieh dismissed their stale review June 2, 2020 09:33

comments were addressed

@pieh pieh removed the status: needs core review Currently awaiting review from Core team member label Jun 2, 2020
Ekwuno
Ekwuno previously requested changes Jun 2, 2020
Copy link
Contributor

@Ekwuno Ekwuno left a comment

Choose a reason for hiding this comment

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

Thanks for sending this in. I left a few comments.

Copy link

@AishaBlake AishaBlake left a comment

Choose a reason for hiding this comment

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

This looks good! Thank you for your patience, @BobWall23. And thanks to the other team members who have already reviewed! I've fixed a couple of merge conflicts and will merge this once tests pass.

@AishaBlake AishaBlake dismissed Ekwuno’s stale review June 24, 2020 09:36

notes addressed

@AishaBlake
Copy link

Note: this says that we still need a Code owner review from the core team but pieh signed off on this a while back!

@AishaBlake AishaBlake merged commit 2b68c84 into gatsbyjs:master Jun 24, 2020
@gatsbot
Copy link

gatsbot bot commented Jun 24, 2020

Holy buckets, @BobWall23 — 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!

pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
…ppets (gatsbyjs#24512)

* Add the ability to embed named snippets

Makes it possible for someone to add inline comments to a source file
delineating one or more named snippets, and to embed snippets by name.

* Modified syntax to better match prismjs

Based on review feedback, changed from `#SN<snippetName>` to
`{snippet: "snippetName"}`. Also, marking the named snippet in
the referenced file uses `start-snippet{snippetName}` and
`end-snippet{snippetName}` instead of `BEGIN SNIPPET snippetName`
and `END SNIPPET snippetName`.

This syntax is used by prismjs for other option selections and
inline comments.

* Code reformatter

* Fix lint errors

* Update packages/gatsby-remark-embed-snippet/README.md

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>

* Update packages/gatsby-remark-embed-snippet/README.md

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>

* Fix lint error

* Reworked code to find named snippet.

Based on PR review, changed code to find the start and end of the
snippet to use regular expressions. Nicer, easier to understand.

* Incorporate PR review feedback

* Address PR review feedback

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
Co-authored-by: Aisha Blake <aisha@gatsbyjs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: remark/mdx Related to Markdown, remark & MDX ecosystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants