[gatsby-remark-prismjs] allow adding PrismJS plugins #20642
Replies: 26 comments 3 replies
-
@muuvmuuv I don't think we have a generic way to use plugins with |
Beta Was this translation helpful? Give feedback.
-
I'd love to if I would have time, I'm pretty in hurry to get my portfolio done to apply for a new job, so not much time for OSS right now. It was just something I noticed while polishing everything up. Hopefully someone else will have the same issue and more time than me :) |
Beta Was this translation helpful? Give feedback.
-
@muuvmuuv Totally understand! Hopefully someone comes along and want's to jump in! If anyone wants to, ping here and I'd be more than happy to point you in the right direction! |
Beta Was this translation helpful? Give feedback.
-
@blainekasten I was wondering how Gatsby's website is able to display language and copy to clipboard feature as seen in the photo below. |
Beta Was this translation helpful? Give feedback.
-
Hello @muuvmuuv ! Do you mean that
Should be wrapped for the Gatsby plugin system. Resulting in something like this:
Are my suppositions correct? |
Beta Was this translation helpful? Give feedback.
-
A custom code block for MDX and some CSS: https://github.com/gatsbyjs/gatsby/blob/master/www/src/components/code-block/index.js
Wrapping them in respective plugins would be the easier thing to do, yes. |
Beta Was this translation helpful? Give feedback.
-
Sounds good to wrap them in Gatsby plugins! The plugins that are included in |
Beta Was this translation helpful? Give feedback.
-
Ok, so it sounds for me that at the end we're going to have six new plugins. Three completely new plugins:
Three extracted from
Questions:
// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-prismjs`,
options: {
plugins: [
{
resolve: `gatsby-prismjs-copy-to-clipboard`,
options: {
// etc. |
Beta Was this translation helpful? Give feedback.
-
Hey @muuvmuuv, @rbelow ! I talked with @LekoArts, and has comment wasn't very clear.
He was just implying that would be easier, but we agree that the right thing to do here is to just add an option for plugins which the user can supply. Take this for inspiration: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-mdx/README.md#md-plugins |
Beta Was this translation helpful? Give feedback.
-
Thanks, @blainekasten . After looking to your link the solution would be something like this: // gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-remark-prismjs`,
options: {
prismjsPlugins: [
require("prismjs/plugins/show-invisibles/prism-show-invisibles"),
require("plugins/show-invisibles/prism-show-invisibles.js"),
// etc.
],
},
},
],
} More questions:
<section>
<h1>Examples</h1>
<pre data-src="plugins/show-invisibles/prism-show-invisibles.js"></pre>
<pre data-src="plugins/show-invisibles/prism-show-invisibles.css"></pre>
<pre data-src="plugins/show-invisibles/index.html"></pre>
</section> This would mean that the
It's nice to make What do you think? |
Beta Was this translation helpful? Give feedback.
-
@rbelow Because GatsbyJS uses webpack, I guess CSS can easily be imported somewhere in your browser config. So JS goes into Plugin dependencies will be required in prismjs so no need to handle this by yourself, I think webpack will bundle them. Why do you want to download the plugins or anything manually? Just |
Beta Was this translation helpful? Give feedback.
-
Thanks, @muuvmuuv . I'll take a look and start today. |
Beta Was this translation helpful? Give feedback.
-
Is the proper way to test the plugin with |
Beta Was this translation helpful? Give feedback.
-
@rbelow im on my phone, so sorry for the short answer. But this doc should help you get a local dev setup https://www.gatsbyjs.org/contributing/setting-up-your-local-dev-environment/ |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
@muuvmuuv In the |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Let's keep the scope of this issue to adding support for prism plugins to the |
Beta Was this translation helpful? Give feedback.
-
Hi! I opened a WIP pull request. The pull request adds the Prism Show Invisibles Plugin to gatsby-remark-prismjs. The original plugin is an IIFE and does not hook into the Prism environment variable of I think we can create a plugin system for I'll add tests to the pull request and wait for your feedback @blainekasten , @acagastya , @muuvmuuv . How we can proceed with the Gatsby documentation? How we can proceed with the two other plugins? |
Beta Was this translation helpful? Give feedback.
-
@blainekasten , @muuvmuuv , @acagastya the pull request is now open. It would be glad to have your feedback. I recommend to open two new issues for the two remaining plugins. Maybe also one for the "pluginization" of |
Beta Was this translation helpful? Give feedback.
-
LGTM for now. Later this would need to be extended by a default plugin Class which defines how plugins should be invoked. |
Beta Was this translation helpful? Give feedback.
-
The PR is now merged, @muuvmuuv . How do you proceed normally with the documentation @blainekasten ? Should a new issue be opened for the documentation update or should it be done within the scope of this one? When can this issue be closed (is there something like a definition of done)? For the other two plugins you mentioned @muuvmuuv : Is still a need for them? Do you want to open two new issues for them? @muuvmuuv , @blainekasten , @acagastya , @LekoArts do you think there is a real need for a further "pluginization" of |
Beta Was this translation helpful? Give feedback.
-
Hey @rbelow, not now. I have anyway coded it my own with https://github.com/muuvmuuv/portfolio/blob/master/src/components/Code.jsx |
Beta Was this translation helpful? Give feedback.
-
@blainekasten @LekoArts @rbelow Also, you can mark this comment as off-topic. |
Beta Was this translation helpful? Give feedback.
-
@manishsundriyal I have written an article explaining: how to set up your local environment. Please, contact me if something in the guide doesn't work as expected or it's hard to understand. |
Beta Was this translation helpful? Give feedback.
-
Hey @rbelow ! I checkout out your PR that you merged earlier and was wondering would other plugins be added in the same way? So what I am referring to is the https://prismjs.com/plugins/copy-to-clipboard/ plugin. Your PR only added the show invisibles prism plugin, not sure if there is another issue involved with the copy-to-clipboard plugin. I, similar to @muuvmuuv, am wondering how to incorporate a copy to clipboard functionality to my code block snippet generated by the Thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
PrismJS has great plugins that I would like to use, e.g.:
I'm not sure if this is already possible but couldn't find any reference in the docs. Would be pretty great to allow passing plugins.
Basic example
Motivation
This would allow me to have the same awesome code highlighter as the Gatsby docs themselves.
Beta Was this translation helpful? Give feedback.
All reactions