npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@md-plugins/md-plugin-codeblocks

v0.1.0-alpha.10

Published

A markdown-it plugin for code blocks.

Downloads

621

Readme

md-plugin-codeblocks

A Markdown-It plugin that enhances code block rendering by providing syntax highlighting, line numbering, and support for advanced features like tabbed code blocks. It integrates with Prism.js for syntax highlighting and allows customization for various use cases.

Features

  • Syntax Highlighting: Automatically highlights code blocks using Prism.js.
  • Line Numbering: Optionally adds line numbers to code blocks.
  • Magic Comments: Supports special comments like [[! highlight]], [[! add]], and [[! rem]] for inline code annotations.
  • Tabbed Code Blocks: Enables the creation of tabbed code blocks for multi-language or multi-file examples.
  • Customizable Components: Supports custom wrapper and copy button components.
  • Fallback for Unsupported Languages: Gracefully handles code blocks written in unsupported languages.

Installation

Install the plugin via your preferred package manager:

# With npm:
npm install @md-plugins/md-plugin-codeblocks
# Or with Yarn:
yarn add @md-plugins/md-plugin-codeblocks
# Or with pnpm:
pnpm add @md-plugins/md-plugin-codeblocks

Usage

Basic Setup

import MarkdownIt from 'markdown-it'
import { codeblocksPlugin } from '@md-plugins/md-plugin-codeblocks'

const md = new MarkdownIt()
md.use(codeblocksPlugin, {
  containerComponent: 'MarkdownPrerender',
  copyButtonComponent: '<MarkdownCopyButton',
  preClass: 'markdown-code',
  pageScripts: [
    "import MarkdownPrerender from 'src/.q-press/components/MarkdownPrerender'",
    "import MarkdownCopyButton from 'src/.q-press/components/MarkdownCopyButton.vue'",
  ],
})

Example Markdown Input

console.log('Hello, world!')

Example Output

The rendered output will include syntax-highlighted code wrapped in customizable components:

<markdown-prerender>
  <pre v-pre class="markdown-code language-javascript">
    <code>
      console<span class="token punctuation">.</span>
      <span class="token function">log</span>
      <span class="token punctuation">(</span>
      <span class="token string">'Hello, world!'</span>
      <span class="token punctuation">)</span>
      <span class="token punctuation">;</span>
    </code>
  </pre>
  <markdown-copy-button></markdown-copy-button>
</markdown-prerender>

Options

The md-plugin-codeblocks plugin supports the following options:

| Option | Type | Default | Description | | ------------------- | ------ | ---------------------- | -------------------------------------------------------------- | | defaultLang | string | 'markup' | Default language for code blocks without a specified language. | | containerComponent | string | 'markdown-prerender' | Custom wrapper component for code blocks. | | copyButtonComponent | string | 'markdown-copy-button' | Custom copy button component. | | preClass | string | 'markdown-code' | CSS class for the <pre> element. | | codeClass | string | '' | CSS class for the <code> element. | | tabPanelTagName | string | 'q-tab-panel' | Tag name for the tab panels. | | tabPanelTagClass | string | 'q-pa-none' | CSS class for the tab panels. |

Advanced Features

Line Numbering

The plugin supports magic comments for inline annotations:

```js [numbered]
// All lines will be numbered
console.log('Line 1')
console.log('Line 2')
console.log('Line 3')
```

Line Highlighting and Annotations

```js [highlight=2]
console.log('Line 1')
console.log('Line 2') // This line will be highlighted
console.log('Line 3')
```
```js
console.log('Line 1')
console.log('Line 2') [[highlight]] // This line will be highlighted
console.log('Line 3')
```
```js [add=2]
console.log('Line 1')
console.log('Line 2') // This line will be accented and prefixed with a '+'
console.log('Line 3')
```
```js [rem=2]
console.log('Line 1')
console.log('Line 2') // This line will be accented and prefixed with a '-'
console.log('Line 3')
```

Combining Annotations

```js [numbered highlight=1 rem=2 add=3]
console.log('Line 1') // This line will be highlighted
console.log('Line 2') // This line will be accented and prefixed with a '-'
console.log('Line 3') // This line will be accented and prefixed
```

Using Ranges

Additonally, with the exception of numbered, you can use ranges to annotate multiple lines:

[highlight=1,10-11 add=4,7-9 rem=12-14]

Tabbed Code Blocks

Easily create tabbed interfaces for multiple code examples:

```tabs
<<|js Tab 1|>>
console.log('Hello from Tab 1');

<<|ts Tab 2|>>
console.log('Hello from Tab 2');
```

Testing

Run the unit tests with Vitest:

pnpm test

Documentation

In case this README falls out of date, please refer to the documentation for the latest information.

License

This project is licensed under the MIT License. See the LICENSE file for details.