[demo] Make syntect an optional dependency
Adds a whopping 1.4 MB to the WASM
This commit is contained in:
parent
7336df53b7
commit
e529bd3ea4
2 changed files with 15 additions and 1 deletions
|
@ -30,7 +30,7 @@ criterion = { version = "0.3", default-features = false }
|
|||
|
||||
[features]
|
||||
default = []
|
||||
http = ["image", "syntect", "epi/http"]
|
||||
http = ["image", "epi/http"]
|
||||
persistence = ["epi/persistence", "serde"]
|
||||
|
||||
[[bench]]
|
||||
|
|
|
@ -196,6 +196,7 @@ fn ui_resouce(
|
|||
// ----------------------------------------------------------------------------
|
||||
// Syntax highlighting:
|
||||
|
||||
#[cfg(feature = "syntect")]
|
||||
fn syntax_highlighting(response: &Response) -> Option<ColoredText> {
|
||||
let text = response.text.as_ref()?;
|
||||
let extension_and_rest: Vec<&str> = response.url.rsplitn(2, '.').collect();
|
||||
|
@ -204,8 +205,10 @@ fn syntax_highlighting(response: &Response) -> Option<ColoredText> {
|
|||
}
|
||||
|
||||
/// Lines of text fragments
|
||||
#[cfg(feature = "syntect")]
|
||||
struct ColoredText(Vec<Vec<(syntect::highlighting::Style, String)>>);
|
||||
|
||||
#[cfg(feature = "syntect")]
|
||||
impl ColoredText {
|
||||
/// e.g. `text_with_extension("fn foo() {}", "rs")`
|
||||
pub fn text_with_extension(text: &str, extension: &str) -> Option<ColoredText> {
|
||||
|
@ -247,6 +250,17 @@ impl ColoredText {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "syntect"))]
|
||||
fn syntax_highlighting(_: &Response) -> Option<ColoredText> {
|
||||
None
|
||||
}
|
||||
#[cfg(not(feature = "syntect"))]
|
||||
struct ColoredText();
|
||||
#[cfg(not(feature = "syntect"))]
|
||||
impl ColoredText {
|
||||
pub fn ui(&self, _ui: &mut egui::Ui) {}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Texture/image handling is very manual at the moment.
|
||||
|
||||
|
|
Loading…
Reference in a new issue