Recently I was faced with a problem of how can I use code snippets for our company's Technical blog, as we were moving from the old blog to our new one here in HubSpot. I was not able to find a straightforward step-by-step guide, so I ended up finding out how to do it myself and writing this blog post.
So what is Prism.js in the first place, according to www.prismjs.com it is "a lightweight, extensible syntax highlighter, built with modern web standards in mind. It’s used in millions of websites, including some of those you visit daily." Prism.js is highly configurable and you can actually choose the theme and even the languages you want your syntax highlighter to support. The latter feature is really neat, because you will be able to control what you need and what you don't and also make your bundle less heavy.
To be able to add Prims.js to your Hubspot blog, you first need to download the Prism.js files.
js
and css
files.css
file something like prism.css
and copy it to website/assets/build/css js
file something like prism.js
and copy it to website/assets/build/js/distprismconfig.js
file and copy it to the same folder that you have pasted your prism.js
file, the contents of the file should be:Once you are done with this, we will proceed with creating the Code Block Module. It is important that you have copied all the files because we will need to attach them to the Code Block Module.
Now that we have all the needed files in all the needed folders, we can start creating the Code Block Module.
module.html
, module.css
, module.js
module.html
section:These are the input values of your Code Block Module, which we will configure next.
Now that you have created your file and saved the HTML code, head to the right pane and configure the Code Block Module setup fields:
Now, we will need to link the Prism.js files that we have added:
prism.css
prism.js
and prismconfig.js
for the Javascript section.Once you are done with all the steps, you are good to go with your first usage of your Code Block Module
Now, when creating any blog post, you can select your code-block module from the Add to Page section by searching for the name of your module. You can then select the language you want to format and add the content.
Have fun using it!