How to Add Syntax Highlighting PrismJS to Nuxt

featured Image

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 prism to 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.

configure prismjs theme in nuxtjs

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:

Remove Trailing Slash from URL in Nuxt + Netlify

How To Run Netlify CMS Admin Locally?

Related Posts

featured Image

How To Add Robots.txt in your Nuxtjs Application

Here in this article, we will see how to add a robot.txt file in our nuxtjs application after it is built or generated before deployment. Before learning the steps to…

Read more
featured Image

How To Add Font Locally In Nuxt App

In this tutorial, we will learn the step-by-step process of how to add a custom google font locally in your nuxtjs application. You can either use a premium font or…

Read more
featured Image

How To Add Google Font in Nuxt Application

Here in this article we will see how to add google font in your nuxtjs project/application. The process is really simple you just have to import the google font link…

Read more