[Feat] add more language highlighting using two-face (#56)
parent
c10dd114ba
commit
8e9b4489b6
|
@ -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"
|
||||||
|
|
|
@ -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"]
|
||||||
|
|
|
@ -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}")]
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue