Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lezer/highlight

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lezer/highlight

Highlighting system for Lezer parse trees

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by3.38%
Maintainers
1
Weekly downloads
 
Created

What is @lezer/highlight?

@lezer/highlight is a syntax highlighting library that works with the Lezer parser system. It allows you to define and apply syntax highlighting rules to code parsed by Lezer parsers.

What are @lezer/highlight's main functionalities?

Defining Highlighting Styles

This feature allows you to define custom highlighting styles for different syntax elements like keywords, strings, and comments.

const { styleTags, tags } = require('@lezer/highlight');

const myHighlighting = styleTags({
  Keyword: tags.keyword,
  String: tags.string,
  Comment: tags.comment
});

Applying Highlighting to Parsed Code

This feature allows you to apply the defined highlighting styles to a parsed syntax tree, and it logs the highlighted ranges and their corresponding classes.

const { highlightTree } = require('@lezer/highlight');
const { parser } = require('lezer-python');
const { defaultHighlightStyle } = require('@codemirror/highlight');

const code = 'def my_function():\n    return "Hello, World!"';
const tree = parser.parse(code);

highlightTree(tree, defaultHighlightStyle.match, (from, to, classes) => {
  console.log(`Highlight ${from}-${to}: ${classes}`);
});

Other packages similar to @lezer/highlight

FAQs

Package last updated on 13 Aug 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc