[Feat] add more language highlighting using two-face (#56)
parent
c10dd114ba
commit
8e9b4489b6
|
@ -407,6 +407,7 @@ dependencies = [
|
|||
"syntect",
|
||||
"thiserror",
|
||||
"tiny-skia",
|
||||
"two-face",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1276,6 +1277,17 @@ version = "0.20.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.15"
|
||||
|
|
|
@ -12,6 +12,7 @@ serde = "1.0.197"
|
|||
arboard = {features = ["wayland-data-control"], version = "3.3.2"}
|
||||
thiserror = "1.0.58"
|
||||
regex = "1.10.3"
|
||||
two-face = "0.3.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
|
|
@ -8,7 +8,7 @@ pub enum RenderError {
|
|||
#[error("Highlight code failed!")]
|
||||
HighlightThemeLoadFailed,
|
||||
|
||||
#[error("Find Highlight theme for {0} failed")]
|
||||
#[error("No such highlight syntax for {0}")]
|
||||
HighlightCodeFailed(String),
|
||||
|
||||
#[error("Unable to parse unknown background theme {0}")]
|
||||
|
|
|
@ -2,7 +2,6 @@ use cosmic_text::{Attrs, Family, Style, Weight};
|
|||
use syntect::{
|
||||
easy::HighlightLines,
|
||||
highlighting::{FontStyle, ThemeSet},
|
||||
parsing::SyntaxSet,
|
||||
util::LinesWithEndings,
|
||||
};
|
||||
|
||||
|
@ -37,7 +36,7 @@ impl Highlight {
|
|||
theme_folder: &str,
|
||||
theme: &str,
|
||||
) -> 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)
|
||||
.map_err(|_| RenderError::HighlightThemeLoadFailed)?;
|
||||
let syntax = match &self.extension {
|
||||
|
|
Loading…
Reference in New Issue