-
Notifications
You must be signed in to change notification settings - Fork 1.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
JSON formatting breaks inside Docusaurus2 #3066
Comments
Your Prism setup is weird. The JSON code is clearly highlighted as JSON (SSR I reckon) but the client-side instance of Prism doesn't have JSON. Same with the Copy to clipboard plugin. That JSON code block clearly has a Copy button but your client-side Prism instance doesn't have that plugin loaded. Even weirder: the client-side Prism instance only gets loaded after you hover over those links. The causeI think this lazy loading is the problem. Prism will auto highlight all code blocks on a page when loaded if What happens is the following:
So why is the code reformatted? SolutionsThe problem is Prims re-highlighting the entire page. The solution is simple: Set Also, this fix has to be applied by whichever library loads/uses Prism. You can apply this fix on your website right now but please make an issue for the library responsible so they can fix it for everyone. |
Thanks a lot @RunDevelopment, this is great news 👍 Let's ping @slorber. Is it something that can be set by default in Docusaurus? |
Hey, I'm on holiday soon so can't investigate much, but the Docusaurus site is able to render json properly: https://docusaurus.io/docs/next/browser-support#default-values So I guess the issue is related to @arthurflageul 's site specificities
We have a webpack config to optimize the loading of Prism packages and reduce bundle size (if I remember correctly): configureWebpack() {
const prismLanguages = additionalLanguages
.map((lang) => `prism-${lang}`)
.join('|');
return {
plugins: [
new ContextReplacementPlugin(
/prismjs[\\/]components$/,
new RegExp(`^./(${prismLanguages})$`),
),
],
};
},
We don't use a copy to clipboard plugin, it's code from Docusaurus I know we have a quite unusual setup (that I didn't work on much) and Prism is likely not the problem here. I don't think Docusaurus either because we render json correctly, as well as many other doc sites (it's not like json is not a popular language...) @arthurflageul I already mentioned this is not valid JSON: "effects": [ { "campaignId": 377, "rulesetId": 1096, "ruleIndex": 0, "ruleName": "25% off", "effectType": "setDiscount", "triggeredByCoupon": 97534, "props": { "name": "25% off", "value": 66.25 } Please add |
Information:
Description
Go on any page of this website that contains a code block. Hover over the top-right links to the API reference docs, and the code blocks of the current page break.
It's a website built with Docusaurus2. I've reported the issue to them, but it doesn't seem to come from them, and I can't figure out the issue so I'm thinking it's part of Prism.
Example of formatted code block:
The same code block but broken:
Somehow,
codeBlockLines_39YC
loses its javascript class.Let me know if you need extra information.
The text was updated successfully, but these errors were encountered: