Skip to content

mbenja/highlight-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

highlight-rs

A syntax highlighter written in Rust.

This project was just for fun and served as a good learning experience for the Rust programming language. highlight-rs is not a feature complete syntax highlighter. While the project is configured to support mulitple languages, right now it only supports (most of) JavaScript.

Example Output

highlight-rs-example-output

Example Usage

use highlight_rs::{highlight, lexer::language::Language};

fn main() {
    let output = highlight("let myVar = 123;", Language::JavaScript);
}

Benchmarks

Despite not being feature complete, highlight-rs is quite fast. The lexical analysis doesn't use regular expressions and instead reads each character of the input string individually, without back-tracking, to tokenize the input. This means that highlight-rs performs favorably against other solutions. Being written in Rust also helps!

Here is a comparison against a popular syntax highlighter written in JavaScript, highlight.js. Each library was given a JavaScript file containing 1000 lines of code, below are the average results of 1000 iterations.

highlight-rs highlight.js
1.314719ms 70.998099ms

About

A syntax highlighter written in Rust.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages