# rehype-inline-code-classname

> A rehype plugin to support adding className to inline code blocks

Latest version **1.0.10** (published 2023-07-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install rehype-inline-code-classname
pnpm add rehype-inline-code-classname
yarn add rehype-inline-code-classname
bun add rehype-inline-code-classname
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2023-07-10 |
| First published | 2022-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 10 |
| Unpacked size | 32.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Pedro Marquez |
| Maintainers | pfernandom |
| Keywords | frontmatter, markdown, markdown-frontmatter, mdast, mdx, remark, remark-plugin, toml, unified, xdm, yaml |

## Links

- npm: https://www.npmjs.com/package/rehype-inline-code-classname
- Repository: https://github.com/pfernandom/rehype-inline-code-classname
- Homepage: https://github.com/pfernandom/rehype-inline-code-classname#readme
- Issues: https://github.com/pfernandom/rehype-inline-code-classname/issues
- npm.io page: https://npm.io/package/rehype-inline-code-classname

## Dependencies (10)

- [hast](https://npm.io/package/hast.md) ^1.0.0
- [unified](https://npm.io/package/unified.md) ^10.0.0
- [mdx-to-md](https://npm.io/package/mdx-to-md.md) ^0.3.2
- [@types/mdast](https://npm.io/package/@types/mdast.md) ^3.0.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^4.1.1
- [mdast-util-to-hast](https://npm.io/package/mdast-util-to-hast.md) ^12.2.1
- [@mdx-js/node-loader](https://npm.io/package/@mdx-js/node-loader.md) ^2.3.0
- [mdast-util-from-markdown](https://npm.io/package/mdast-util-from-markdown.md) ^1.2.0
- [estree-util-value-to-estree](https://npm.io/package/estree-util-value-to-estree.md) ^1.0.0
- [estree-util-is-identifier-name](https://npm.io/package/estree-util-is-identifier-name.md) ^2.0.0

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.0.10 (latest) — 2023-07-10
- 1.0.9 — 2022-09-11
- 1.0.8 — 2022-09-11
- 1.0.7 — 2022-08-29
- 1.0.6 — 2022-08-27
- 1.0.4 — 2022-08-27
- 1.0.3 — 2022-08-27
- 1.0.1 — 2022-08-27
- 1.0.0 — 2022-08-27

## README

# rehype-inline-code-classname

A [unified](http://unifiedjs.com/explore/package/unified/)([rehype](http://unifiedjs.com/explore/project/rehypejs/rehype/)) plugin to support adding className to inline code blocks

## Description

This plugin takes inline code blocks in Markdown, and allows users to add a class name to it:

The following Markdown:

```md
`highlighted^const inline = "code";`
```

Gets converted to:

```html
<code class="highlighted"> const inline = "code"; </code>
```

The separator by default is `^`, but it can be changed in the configuration.

### Configuration

- config.separator: [String] The character that separates the class name from the content.
- config.trailing: [Boolean] If true, it will try to find the class name at the end of the string.

#### Option: separator

Using a custom separator:

```js
const result = await unified()
  // using '*' as the separator
  .use(rehypeInlineCodeClassNamePlugin, { separator: "*" });
```

The markdown:

```md
`highlighted*const inline = "code";`
```

Is parsed as:

```html
<code class="highlighted">const inline = "code";</code>
```

#### Option: trailing

```js
const result = await unified()
  // using '*' as the separator
  .use(rehypeInlineCodeClassNamePlugin, { trailing: true });
```

The markdown:

```md
`const inline = "code";^highlighted`
```

Is parsed as:

```html
<code class="highlighted">const inline = "code";</code>
```

### Using unified

```js
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { read } from "to-vfile";

import rehypeInlineCodeClassNamePlugin from "rehype-inline-code-classname";

const result = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeInlineCodeClassNamePlugin)
  // add more plugins
  .process(await read("./test/example.md"));
```

### Using MDX factory (for Next.js)

```js
import withMDXFactory from "@next/mdx";
import rehypeInlineCodeClassNamePlugin from "rehype-inline-code-classname";

const withMDX = withMDXFactory({
  extension: /\.mdx?$/,
  options: {
    rehypePlugins: [rehypeInlineCodeClassNamePlugin],
    providerImportSource: "@mdx-js/react",
  },
});

const nextConfig = withMDX({
  // next.js configuration
});

export default nextConfig;
```

---
_Source: https://npm.io/package/rehype-inline-code-classname · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
