Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

coryhouse
Copy link
Owner

@coryhouse coryhouse commented Jul 2, 2017

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):
screenshot 2017-07-02 11 10 27

As you can see in this pull request, it's a pretty straightforward migration.

Related clips

  • Use Prism instead of highlight.js here
  • Mention Prism here
  • Configure Prism instead here

@@ -0,0 +1,7 @@
/* eslint-disable */
/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+clike+javascript+jsx */
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

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?

Copy link
Owner Author

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?

Copy link

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

  1. download prism.js from the specified url
  2. edit this file and place /* eslint-disable no-eval */ before any javascript

After adding this comment, the errors went away

@bgazzera
Copy link

bgazzera commented Jul 7, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants