forked from slonk/bingus-blog
remove syntect-to-css
This commit is contained in:
parent
76f4e0358b
commit
b0006664e6
3 changed files with 0 additions and 83 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -364,7 +364,6 @@ dependencies = [
|
||||||
"axum 0.7.5",
|
"axum 0.7.5",
|
||||||
"bitcode",
|
"bitcode",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"comrak",
|
"comrak",
|
||||||
"console-subscriber",
|
"console-subscriber",
|
||||||
|
|
|
@ -4,14 +4,9 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "bingus-blog"
|
default-run = "bingus-blog"
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "syntect-to-css"
|
|
||||||
required-features = ["clap"]
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["precompression"]
|
default = ["precompression"]
|
||||||
tokio-console = ["dep:console-subscriber"]
|
tokio-console = ["dep:console-subscriber"]
|
||||||
clap = ["dep:clap"]
|
|
||||||
precompression = ["dep:async-compression"]
|
precompression = ["dep:async-compression"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
@ -27,7 +22,6 @@ async-compression = { version = "0.4.8", optional = true }
|
||||||
axum = { version = "0.7.5", features = ["macros"] }
|
axum = { version = "0.7.5", features = ["macros"] }
|
||||||
bitcode = { version = "0.6.0", features = ["serde"] }
|
bitcode = { version = "0.6.0", features = ["serde"] }
|
||||||
chrono = { version = "0.4.37", features = ["serde"] }
|
chrono = { version = "0.4.37", features = ["serde"] }
|
||||||
clap = { version = "4.5.4", features = ["derive"], optional = true }
|
|
||||||
color-eyre = "0.6.3"
|
color-eyre = "0.6.3"
|
||||||
comrak = { version = "0.22.0", features = ["syntect"] }
|
comrak = { version = "0.22.0", features = ["syntect"] }
|
||||||
console-subscriber = { version = "0.2.0", optional = true }
|
console-subscriber = { version = "0.2.0", optional = true }
|
||||||
|
|
|
@ -1,76 +0,0 @@
|
||||||
use std::fs::File;
|
|
||||||
use std::io::BufReader;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use clap::Parser;
|
|
||||||
use color_eyre::eyre::{self, Context, Ok, OptionExt};
|
|
||||||
use syntect::highlighting::{Theme, ThemeSet};
|
|
||||||
use syntect::html::{css_for_theme_with_class_style, ClassStyle};
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
|
||||||
#[command(about = "generate CSS from a syntect theme")]
|
|
||||||
struct Args {
|
|
||||||
#[command(subcommand)]
|
|
||||||
command: Command,
|
|
||||||
#[arg(
|
|
||||||
short,
|
|
||||||
long,
|
|
||||||
help = "prefix for generated classes",
|
|
||||||
default_value = "syntect-"
|
|
||||||
)]
|
|
||||||
prefix: String,
|
|
||||||
#[arg(
|
|
||||||
long,
|
|
||||||
help = "don't add a prefix to generated classes",
|
|
||||||
default_value_t = false
|
|
||||||
)]
|
|
||||||
no_prefix: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
|
||||||
enum Command {
|
|
||||||
#[command(about = "generate CSS from a theme in the default theme set")]
|
|
||||||
Default {
|
|
||||||
#[arg(help = "name of theme (no .tmTheme)")]
|
|
||||||
theme_name: String,
|
|
||||||
},
|
|
||||||
#[command(about = "generate CSS from a .tmTheme file")]
|
|
||||||
File {
|
|
||||||
#[arg(help = "path to theme (including .tmTheme)")]
|
|
||||||
path: PathBuf,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> eyre::Result<()> {
|
|
||||||
let args = Args::parse();
|
|
||||||
color_eyre::install()?;
|
|
||||||
|
|
||||||
let theme = match args.command {
|
|
||||||
Command::Default { theme_name } => {
|
|
||||||
let ts = ThemeSet::load_defaults();
|
|
||||||
ts.themes
|
|
||||||
.get(&theme_name)
|
|
||||||
.ok_or_eyre(format!("theme {:?} doesn't exist", theme_name))?
|
|
||||||
.to_owned()
|
|
||||||
}
|
|
||||||
Command::File { path } => {
|
|
||||||
let mut file = BufReader::new(
|
|
||||||
File::open(&path).with_context(|| format!("failed to open {:?}", path))?,
|
|
||||||
);
|
|
||||||
ThemeSet::load_from_reader(&mut file).with_context(|| "failed to parse theme")?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let class_style = if args.no_prefix {
|
|
||||||
ClassStyle::Spaced
|
|
||||||
} else {
|
|
||||||
ClassStyle::SpacedPrefixed {
|
|
||||||
prefix: args.prefix.leak(),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let css = css_for_theme_with_class_style(&theme, class_style)
|
|
||||||
.with_context(|| "failed to generate css")?;
|
|
||||||
println!("{css}");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
Reference in a new issue