New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

rehype-code-language

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-code-language

remark plugin to add a language span element to code blocks

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

rehype-code-language

Remark plugin to add a language span element to code blocks.

Installation

npm install rehype-code-language

Example

import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import rehypeCodeLanguage from 'rehype-code-language'

const markdown = `
  \`\`\`js
  let a = 1;

  console.log(a);
  \`\`\`
  `

const result = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeStringify)
  .use(rehypeCodeLanguage)
  .process(markdown)

The rendered HTML will be

<pre><span class="language">js</span><code class="language-js">let a = 1;

console.log(a);
</code></pre>

Options

defaultLanguage: display default language, if you don't specify language

For example:

import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import rehypeCodeLanguage from 'rehype-code-language'

const markdown = `
  \`\`\`
  some text
  \`\`\`
  `

const result = await unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeStringify)
  .use(rehypeCodeLanguage, { defaultLanguage: 'txt' })
  .process(markdown)

The rendered HTML will be

<pre><span class="language">txt</span><code>some text
</code></pre>

Keywords

rehype

FAQs

Package last updated on 14 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts