# markdown-it-prism

> Highlights code blocks in markdown-it using Prism.

Latest version **4.0.0** (published 2026-07-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install markdown-it-prism
pnpm add markdown-it-prism
yarn add markdown-it-prism
bun add markdown-it-prism
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-07-02 |
| First published | 2016-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20.0.0 |
| Dependencies | 1 |
| Unpacked size | 20.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 95 |
| Author | Joshua Gleitze |
| Maintainers | jgleitz |
| Keywords | markdown-it, markdown-it-plugin, highlight, prism, prismjs |

## Links

- npm: https://www.npmjs.com/package/markdown-it-prism
- Repository: https://github.com/jGleitz/markdown-it-prism
- Issues: https://github.com/jGleitz/markdown-it-prism/issues
- npm.io page: https://npm.io/package/markdown-it-prism

## Dependencies (1)

- [prismjs](https://npm.io/package/prismjs.md) 1.30.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2026-07-02
- 3.0.1 — 2025-11-09
- 3.0.0 — 2025-04-01
- 2.3.1 — 2025-03-11
- 2.3.0 — 2022-08-30
- 2.2.5 — 2022-08-23
- 2.2.4 — 2022-04-17
- 2.2.3 — 2022-02-18
- 2.2.2 — 2022-01-06
- 2.2.1 — 2021-09-16
- 2.2.0 — 2021-08-23
- 2.1.8 — 2021-07-03
- 2.1.7 — 2021-06-27
- 2.1.6 — 2021-03-06
- 2.1.5 — 2021-03-06
- … 17 more at https://npm.io/package/markdown-it-prism/versions

## README

# markdown-it-prism [![CI](https://github.com/jGleitz/markdown-it-prism/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jGleitz/markdown-it-prism/actions/workflows/ci.yml?query=branch%3Amain) [![NPM Version](https://img.shields.io/npm/v/markdown-it-prism?logo=npm&logoColor=%23DDD)](https://www.npmjs.com/package/markdown-it-prism)

> [markdown-it](https://github.com/markdown-it/markdown-it) plugin to highlight code blocks
> using [Prism](http://prismjs.com/)

## Usage

```js
const md = require('markdown-it')();
const prism = require('markdown-it-prism');

md.use(prism, options);
```

The plugin will insert the necessary markup into all code
blocks. [Include one of Prism’s stylesheets](http://prismjs.com/#basic-usage) in
your HTML to get highlighted code.

### Options

The `options` object may contain:

| Name                            | Description                                                                                                                                                                                                                                                                                                                                                       | Default     |
|---------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
| `highlightInlineCode`           | Whether to highlight inline code.                                                                                                                                                                                                                                                                                                                                 | `false`     |
| `plugins`                       | Array of [Prism Plugins](http://prismjs.com/#plugins) to load. The names to use can be found [here](https://github.com/PrismJS/prism/tree/master/plugins). Please note that some prism plugins (notably line-numbers) rely on the DOM being present and can thus not be used with this package (see [#1](https://github.com/jGleitz/markdown-it-prism/issues/1)). | `[]`        |
| `init`                          | A function called after setting up prism. Will receive the prism instance as only argument. Useful for plugins needing further intialisation.                                                                                                                                                                                                                     | `() => {}`  |
| `defaultLanguageForUnknown`     | The language to use for code blocks that specify a language that Prism does not know. No default will be used if this option is `undefined`.                                                                                                                                                                                                                      | `undefined` |
| `defaultLanguageForUnspecified` | The language to use for code block that do not specify a language. No default will be used if this option is `undefined`.                                                                                                                                                                                                                                         | `undefined` |
| `defaultLanguage`               | Shorthand to set both `defaultLanguageForUnknown` and `defaultLanguageForUnspecified` to the same value.                                                                                                                                                                                                                                                          | `undefined` |

### Inline Code

When `highlightInlineCode` is set, inline code will be highlighted just like fenced code blocks are.
To specifiy the language of inline code, add `{language=<your-language>}` after the code segment:

```markdown
`class Demo { };`{language=cpp}
```

### markdown-it-attrs

This plugin is compatible with [markdown-it-attrs](https://github.com/arve0/markdown-it-attrs).
For inline code, the `language` attribute will be interpreted as the highlight language and will _not_ be present as an HTML
attribute.

> [!IMPORTANT]
>  1. For full compatibility, you must use [markdown-it-attrs](https://github.com/arve0/markdown-it-attrs) v5.0.0 or later.
> 2. If you configure `allowedAttributes` for markdown-it-attrs, make sure to include `language`. Otherwise, you will not be able to specify the language of inline code. 

## Usage with Webpack

If you want to use this plugin together with [Webpack](https://webpack.js.org/), you need to import all languages you
intend to use:

```javascript
import MarkdownIt from 'markdown-it';
import prism from 'markdown-it-prism';

import "prismjs/components/prism-clike"
import "prismjs/components/prism-java"

function component() {
    const md = new MarkdownIt();
    md.use(prism);
    const element = document.createElement('div');
    element.innerHTML = md.render(`
Here is some *code*:
\`\`\`java
public class Test {
  public void foo() {}
}
\`\`\`
`);

    return element;
}

document.body.appendChild(component());
```

> [!NOTE]
> Prisms languages have dependencies onto each other. You need to import the languages together with their dependencies in the correct order.

---
_Source: https://npm.io/package/markdown-it-prism · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
