Socket
Book a DemoInstallSign in
Socket

rehype-tree-sitter-highlight

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-tree-sitter-highlight

highlight your code using tree-sitter-highlight

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

rehype-tree-sitter-highlight

highlight your code using tree-sitter-highlight

Installation

npm install rehype-tree-sitter-highlight

Usage

This is a rehype plugin. To highlight code blocks in html:

import fromHtml from 'rehype-parse'
import toHtml from 'rehype-stringify'
import rehypeTreeSitterHighlight from 'rehype-tree-sitter-highlight'
import { unified } from 'unified'

const doc = "```js\nconst hello = 'World';\n```\n"

async function createProcessor() {
  const processor = unified()
    .use(fromHtml)
    .use(rehypeTreeSitterHighlight)
    .use(toHtml)

  return processor
}

const processor = await createProcessor()
const vfile = await processor.process(doc)
console.log(vfile.toString())

Configuration

Theme

Refer to the tree-sitter-highlight docs for information on how to theme the output html.

Supported Languages

Refer to the tree-sitter-highlight for supported languages.

Unknown Languages

Unknown languages are ignored by default. You can set ignoreUnknownLanguage: false to throw an error when an unsupported language is encountered.

Examples

See examples for ways to use this plugin.

Inspiration

Much of the docs and code is taken from rehype-shiki.

Keywords

tree-sitter

FAQs

Package last updated on 24 Dec 2021

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