-
Notifications
You must be signed in to change notification settings - Fork 61
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
Switch to Prism for syntax highlighting #8
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,7 @@ | |||
/* eslint-disable */ | |||
/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+clike+javascript+jsx */ |
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.
Note the address where I downloaded this custom Prism build.
You can see all the options here.
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 wanted to say be careful about adding plugins with this builder. When I tried to add some interesting ones (for example copy to clipboard) It made React puke.
Getting Uncaught DOMException: Failed to execute 'removeChild' on 'Node' when rerendering component
I think this was because one of the plugins changed the DOM without React knowing. I did not test which one was the culprit since I spent hours trying to troubleshoot already.
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.
@coryhouse when you added this file did you not get an error with the WorkerGlobalScope being undefined? Or a bunch of eslint warnings?
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.
Nope, I didn't get any linting issues. If you pull down this branch and run it, do you get any linting issues?
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.
@jjacode: I got the eslint errors you described. I forgot to add the eslint "configuration comment" to prism.js
- download
prism.js
from the specified url - edit this file and place
/* eslint-disable no-eval */
before any javascript
After adding this comment, the errors went away
Thanks a lot! this really helps since we are using CSS Modules, and highlight.js has no support for it. Prism has a plugin that handles this perfectly. |
This pull request shows how to switch from highlight.js (which I currently use in the course demo) to Prism. I suggest using Prism instead of highlight.js because Prism offers superior JSX syntax highlighting.
Note how JSX is properly syntax highlighted via Prism (unlike highlight.js which colors all JSX the same color):
As you can see in this pull request, it's a pretty straightforward migration.
Related clips