[Feat] add more language highlighting using two-face (#56)

This commit is contained in:
Mist 2024-04-02 17:56:40 +08:00 committed by GitHub
parent c10dd114ba
commit 8e9b4489b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 3 deletions

12
generator/Cargo.lock generated
View file

@ -407,6 +407,7 @@ dependencies = [
"syntect", "syntect",
"thiserror", "thiserror",
"tiny-skia", "tiny-skia",
"two-face",
] ]
[[package]] [[package]]
@ -1276,6 +1277,17 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4"
[[package]]
name = "two-face"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37bed2135b2459c7eefba72c906d374697eb15949c205f2f124e3636a46b5eeb"
dependencies = [
"once_cell",
"serde",
"syntect",
]
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.15" version = "0.3.15"

View file

@ -12,6 +12,7 @@ serde = "1.0.197"
arboard = {features = ["wayland-data-control"], version = "3.3.2"} arboard = {features = ["wayland-data-control"], version = "3.3.2"}
thiserror = "1.0.58" thiserror = "1.0.58"
regex = "1.10.3" regex = "1.10.3"
two-face = "0.3.0"
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib"]

View file

@ -8,7 +8,7 @@ pub enum RenderError {
#[error("Highlight code failed!")] #[error("Highlight code failed!")]
HighlightThemeLoadFailed, HighlightThemeLoadFailed,
#[error("Find Highlight theme for {0} failed")] #[error("No such highlight syntax for {0}")]
HighlightCodeFailed(String), HighlightCodeFailed(String),
#[error("Unable to parse unknown background theme {0}")] #[error("Unable to parse unknown background theme {0}")]

View file

@ -2,7 +2,6 @@ use cosmic_text::{Attrs, Family, Style, Weight};
use syntect::{ use syntect::{
easy::HighlightLines, easy::HighlightLines,
highlighting::{FontStyle, ThemeSet}, highlighting::{FontStyle, ThemeSet},
parsing::SyntaxSet,
util::LinesWithEndings, util::LinesWithEndings,
}; };
@ -37,7 +36,7 @@ impl Highlight {
theme_folder: &str, theme_folder: &str,
theme: &str, theme: &str,
) -> Result<Vec<(&str, Attrs)>, RenderError> { ) -> Result<Vec<(&str, Attrs)>, RenderError> {
let syntax_set = SyntaxSet::load_defaults_newlines(); let syntax_set = two_face::syntax::extra_newlines();
let theme_set = ThemeSet::load_from_folder(theme_folder) let theme_set = ThemeSet::load_from_folder(theme_folder)
.map_err(|_| RenderError::HighlightThemeLoadFailed)?; .map_err(|_| RenderError::HighlightThemeLoadFailed)?;
let syntax = match &self.extension { let syntax = match &self.extension {