Skip to content

Syntect Adapter

The syntect feature bridges Opaline themes into the syntect syntax highlighting ecosystem, used by bat, delta, and many other tools.

toml
[dependencies]
opaline = { version = "0.4", features = ["syntect"] }

Color Conversion

OpalineColor converts to syntect::highlighting::Color:

rust
use opaline::OpalineColor;
use syntect::highlighting::Color;

let color = OpalineColor::new(225, 53, 255);
let st_color: Color = color.into();
// → Color { r: 225, g: 53, b: 255, a: 255 }

Style Conversion

OpalineStyle converts to syntect::highlighting::StyleModifier:

rust
use opaline::OpalineStyle;
use syntect::highlighting::StyleModifier;

let style = OpalineStyle::fg(OpalineColor::new(203, 166, 247)).bold().italic();
let modifier: StyleModifier = style.into();
// foreground set, BOLD | ITALIC font_style

Modifier mapping:

OpalineStyleFontStyle
boldBOLD
italicITALIC
underlineUNDERLINE

Theme Generation

Convert a full Opaline theme to a syntect Theme:

rust
use opaline::adapters::syntect::to_syntect_theme;

let theme = opaline::Theme::default();
let syntect_theme = to_syntect_theme(&theme);

// Use with syntect's highlighter
use syntect::highlighting::ThemeSet;
use syntect::parsing::SyntaxSet;
use syntect::easy::HighlightLines;

let ps = SyntaxSet::load_defaults_newlines();
let syntax = ps.find_syntax_by_extension("rs").unwrap();
let mut h = HighlightLines::new(syntax, &syntect_theme);

Token → Scope Mapping

The adapter maps Opaline's generic core tokens to standard TextMate scopes:

Opaline TokenTextMate Scope
code.keywordkeyword
code.stringstring
code.commentcomment
code.functionentity.name.function, support.function
code.numberconstant.numeric
code.typeentity.name.type, support.type
code.line_numberconstant.numeric.line-number
accent.primaryvariable
accent.secondarystorage.type, storage.modifier
accent.tertiaryconstant.other, variable.other.constant
successmarkup.inserted
warningmarkup.changed
errorinvalid, message.error
infostring.other.link, support.constant

ThemeSettings Mapping

Editor-level settings are derived from semantic tokens:

Opaline TokenThemeSettings Field
text.primaryforeground
bg.basebackground
accent.primarycaret, accent
bg.highlightline_highlight
bg.selectionselection
bg.panelgutter
text.dimgutter_foreground
border.focusedactive_guide
border.unfocusedguide

Style Modifiers

If a named style exists that matches a code.* token (for example, keyword for code.keyword), its modifiers are included in the generated scope.

Released under the MIT License.