-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Enable using Prism for syntax highlighting #735
Conversation
Deploy preview for docusaurus-preview ready! Built with commit 0b518ed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
I think package-lock.json
will need to be updated for this as well, in addition to you yarn.lock
?
@iRoachie would this work for you?
Looks GTM, is possible to have a |
That is doable. But it still fall back to hljs if the language is not supported by prism. Additionally, I think user can override the prismJS css we use on their custom.css |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am good with this.
I would like a second approve from @yangshun on this, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes just for discussion. Is it possible to lazy load the CSS only when the user sets usePrism
? I don't think it's good to add CSS payload to all Docusaurus users when only a fraction of them will use Prism styling. I made a similar comment for the scroll to top button script but on hindsight should have also asked for it for the CSS.
lib/core/renderMarkdown.js
Outdated
return hljs.highlight(lang, str).value; | ||
if ( | ||
siteConfig.usePrism === true || | ||
(siteConfig.usePrism && siteConfig.usePrism.indexOf(lang) !== -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use siteConfig.usePrism.length > 0
to be safer.
lib/static/css/main.css
Outdated
@@ -1871,3 +1871,134 @@ footer .social { | |||
flex-shrink: 0; | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This increases the CSS payload to all Docusaurus users, even though not all of them will use it. Is it possible to lazy load the CSS if usePrism
is true
?
Actually this main.css is a slightly modified version. I hacked it a little bit (like removing background) because if I don't, it can conflict with hljs theme. Is this okay for you ? // Head.js
{this.props.config.usePrism && (
<link
rel="stylesheet"
href={this.props.config.baseUrl + 'css/prism.css'}
/>
)} I would love to use CDN but I've mentioned the problem above. Should I upload it somewhere & upload it to CDN ? |
Leaving to @yangshun to approve. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making it in a separate CSS file helps. Thanks @endiliey!
Finally got to try this out guys! Looks great. Encountered some small ux problems with the missing languages -- logged them in this ticket #1076 |
Motivation
Resolves #438
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Production Test
https://deploy-preview-735--docusaurus-preview.netlify.com/docs/en/next/doc-markdown#using-prism-as-additional-syntax-highlighter
Local Test
Go to http://localhost:3000/docs/en/next/doc-markdown & scroll down