The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Highlight Code In Rust With syntect

TL;DR

This is how I'm highlighting HTML strings in Rust which I use to build my site.

TODO: Pull subtitle into page object
code_start_default_section code_end_default_section

Notes

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Highlight Code In Rust With syntect

-- todo

[] look at this and combine it: id: 2ujekgik


-- tldr/

This is how I'm highlighting HTML strings
in Rust which I use to build my site. 

-- code/

use minijinja::Error;
use syntect::highlighting::ThemeSet;
use syntect::html::highlighted_html_for_string;
use syntect::parsing::SyntaxSet;

pub fn highlight_html(name: String) -> Result<String, Error> {
    let ss = SyntaxSet::load_defaults_newlines();
    let ts = ThemeSet::load_defaults();
    let theme = &ts.themes["base16-ocean.dark"];
    let html = highlighted_html_for_string(name.as_str(), &ss, &ss.syntaxes()[1], theme).unwrap();
    Ok(html)
}

-- /code

-- /tldr


-- notes

- It took a while to figure out the `&ss.syntaxes()[1]`` 
part based off the docs. 

- I don't understand what's going on there either. 
Something to investigate. 

- TODO is to look at this for a possibly simpler
way: https://docs.rs/syntect/latest/syntect/easy/struct.HighlightLines.html


-- ref
-- url: https://docs.rs/syntect/latest/syntect/easy/struct.HighlightLines.html

-- ref
-- url: https://docs.rs/syntect/latest/syntect/parsing/struct.SyntaxReference.html

-- ref
-- url: https://docs.rs/syntect/latest/syntect/html/fn.highlighted_html_for_string.html




-- categories
-- Rust 

-- metadata
-- date: 2023-08-09 19:31:29
-- id: 2tli65qo
-- site: aws
-- type: post
-- status: scratch