syntect_minecraft_highlighting

Crates.iosyntect_minecraft_highlighting
lib.rssyntect_minecraft_highlighting
version0.1.0
sourcesrc
created_at2024-11-04 21:23:42.928675
updated_at2024-11-04 21:23:42.928675
descriptionHighlight code with Minecraft formatting
homepage
repositoryhttps://github.com/phoenixr-codes/syntect_minecraft_highlighting
max_upload_size
id1435726
size22,259
Jonas (phoenixr-codes)

documentation

README

syntect Minecraft Highlighting

This crate contains a function for highlighting styled fragments created by syntect with Minecraft Formatting.

Example

use syntect::easy::HighlightLines;
use syntect::highlighting::{Style, ThemeSet};
use syntect::parsing::SyntaxSet;
use syntect::util::LinesWithEndings;
use syntect_minecraft_highlighting::as_minecraft_bedrock_escaped;

fn main() {
    let ps = SyntaxSet::load_defaults_newlines();
    let ts = ThemeSet::load_defaults();

    let syntax = ps.find_syntax_by_extension("rs").unwrap();
    let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 { 42 }\n";

    let mut h = HighlightLines::new(syntax, &ts.themes["base16-ocean.light"]);
    for line in LinesWithEndings::from(s) {
        let ranges: Vec<(Style, &str)> = h.highlight_line(line, &ps).unwrap();
        let escaped = as_minecraft_bedrock_escaped(&ranges[..]);
        println!("{}", escaped);
    }
}
Commit count: 1

cargo fmt