Re-render Prism.js On New Code
I recently switched to use a new syntax highlighter called Prism.js, unlike other highlighters Prism.js is extremely lightweight by default and you can append additional add-ons to library for more options or new themes.
There are currently 6 different themes that you can choose from, you can select which themes to include with the package at download. You can choose to just download the default theme or include all themes. Prism.js is designed to be very lightweight so adding additional features and themes will therefore increase the size of the package.
Therefore you need a way re-rendering the Prism object again to render all code on the page.
Using the method highlightAll() Prism will go through the page search for pre and code tags and re-render all of them to style them correctly.
var precode = document.getElementById('application-code') Prism.highlightElement(precode);
Gain access to all tutorials
- Premium tutorials covering WordPress, Laravel and VueJS
- Download premium content
- Download premium WordPress plugins
- Only $5 a month
Join the weekly newsletter
Sign up for our newsletter. You'll be updated on new tutorials as they come available.