How to Add Syntax Highlighting PrismJS to Nuxt
This article is about how to add a code syntax highlighter PrismJS to Nuxt and configure PrismJs theme in NuxtJS.
This article we will see how to add PrismJs to Nuxt to highlight our code snippets. We will add the prismJs to our nuxt content static site.
PrismJs is a light weight syntax highlighter which is built with modern web standard and have many programming language syntax supports.
PrismJs is very small in size, its 2 KB minified and g-zipped and the theme is less then 1 KB.
In this article, we will add prismJS to NuxtJS application with @nuxt/content module.
In Nuxt Content , PrismJS module handles all code highlighting in markdown content. It helps us to add the desired PrismJS theme easily in our Nuxt.js config file. You can easily change the theme if you don't like the default one.
Add PrismJs to Nuxt Content
To add Prismjs syntax highlighter module to nuxt content we need to install the package.
npm install prism-themes //FOR YARN// yarn add prism-themes
Configure PrismJs in nuxt
The configuration is very simple just add the following code in the nuxt.config.js file.
content: { markdown: { prism: { theme: 'prism-themes/themes/prism-material-oceanic.css' } } }
NOTE : To disable the them, just set
prismto false.
content: { markdown: { prism: { theme: false } } }
How to change prismjs theme in nuxt?
To change the theme , you just have to change the theme property URL in the nuxt.config.js file. You can browse through the different themes here. Once you find it desire theme, click the link and copy the last css part from the url and paste it to your config file.

Now add it the theme property
content: { markdown: { prism: { theme: 'prism-themes/themes/prism-atom-dark.css' } } }
That's how you can easily add prismjs in your nuxt content and highlight your code syntax in blogs.
Related Topics:
Related Posts
How to add common header and footer in Nuxt
Short post on how to add common header and footer component for all your pages in your nuxt application using layouts directory.
How to add external script tag in head in Nuxt
To add external javascript script in nuxt we have to add the script tag with src in the head() method.
Convert image to webp in nuxtjs | Image Optimization
To optimize an image in nuxt we have to use the @nuxt/image module. It can convert an image to webp format in nuxt application.
How to add custom static 404 error page in Nuxt ?
This article is about how to add a custom static 404 page in our nuxt application. 404 error page willbe the fallback page if a page is not found in the static site.
