rehype-inline-code-language
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

rehype-inline-code-language

A Rehype plugin that allows passing a language to inline code. This is useful for syntax highlighting.

Note: This is not a standard markdown feature.

Example

`_js console.log()`

Installation

npm i -D remark-inline-code-language
import { unified } from "unified"
import { visit } from "unist-util-visit"
import remarkParse from "remark-parse"
import remarkRehype from "remark-rehype"
import rehypeStringify from "rehype-stringify"
import rehypeInlineCodeLanguage from "rehype-inline-code-language"

const file = await unified()
	.use(remarkParse)
	.use(remarkRehype)
	.use(rehypeInlineCodeLanguage)
	.use(rehypeStringify)
	.process("`_js console.log()`")

console.log(String(file))
<p><code class="language-js">console.log()</code></p>

Options

You can customize the syntax!

If you are going to only change 1 option, sadly you need to add in all other options too.

.use(rehypeInlineCodeLanguage, {
	// ...
})

separator_character

This is the character(s) that separates the language name from the code content itself.

  • Type: string
  • Default: "_"

Examples

  • "_" => _js console.log()
  • "+" => +js console.log()
  • "=" => =js console.log()

separator_position

  • Type: "before" | "after" | "both"
  • Default: "before"

Examples

  • "before" => _js console.log()
  • "after" => js_ console.log()
  • "both" => _js_ console.log()

/rehype-inline-code-language/

    Package Sidebar

    Install

    npm i rehype-inline-code-language

    Weekly Downloads

    3

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    7.81 kB

    Total Files

    7

    Last publish

    Collaborators

    • babakfp