-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
New lines on code blocks get stripped when using rehype-prism #221
Comments
Hey! I've been away on holidays for a while so I need some time to catch up, but I just wanted to say thanks for being so excellent at reporting issues! ⭐️ |
Thank you! Also, don't worry about it, this is for a personal project so I'm not on a deadline 😀 |
@hugmanrique feel free to help out with this issue, I'm having trouble pinning down where the problem happens. 😕 |
Thank you for the quick fix! 😀 |
I'm getting started with MDX, it's really nice so far, @silvenon are you interested in having example config for use with Prism.js or other syntax highlighting lib? We could have a section in the docs for that. If you can drop the fix on npm when you have time that'd be appreciated :) thanks again! |
Sure! There is just one thing I don't understand about @mapbox/rehype-prism. It places the |
Adding the class to the code tag is what is suggested by the Prism docs, which reference the HTML spec. I do see that if you inspect the Prism or MDN websites, both pre and code have the language class — which I assume is because when Prism executes at runtime it ends up messing with that. I'd be open to a PR adding the language class to both of the elements. |
Thanks! We can continue tracking this in #253. |
New lines sometimes get stripped from the
@mapbox/rehype-prism
output when highlighting a code block.I'm using the following Webpack loader:
The following
.mdx
file:And here's the result:

React source (produced by
@mdx-js/loader
): https://paste.ubuntu.com/p/C3cyx5ZYjV/Which React renders as:
As you can see, there should be a line break between the first
.token .comment
(# Add main script
) and the following.token .keyword
(COPY
).One of the reasons why this could be happening is the
@mdx-js/loader
output is an array of react components, so newlines produced by rehype plugins might not be preserved. I haven't looked to much into it, so I might be wrong.I also didn't know whether to report this on the
rehype-prism
repo or here, but I couldn't reproduce it with a barebones remark setup.The text was updated successfully, but these errors were encountered: