zola/components/config/examples/generate_sublime.rs

46 lines
1.8 KiB
Rust
Raw Normal View History

2017-03-20 08:30:50 +00:00
//! This program is mainly intended for generating the dumps that are compiled in to
//! syntect, not as a helpful example for beginners.
//! Although it is a valid example for serializing syntaxes, you probably won't need
//! to do this yourself unless you want to cache your own compiled grammars.
extern crate syntect;
2018-10-09 12:33:43 +00:00
use syntect::parsing::SyntaxSetBuilder;
2017-03-20 08:30:50 +00:00
use syntect::highlighting::ThemeSet;
use syntect::dumps::*;
use std::env;
fn usage_and_exit() -> ! {
println!("USAGE: cargo run --example generate_sublime synpack source-dir newlines.packdump nonewlines.packdump\n
cargo run --example generate_sublime themepack source-dir themepack.themedump");
2017-03-20 08:30:50 +00:00
::std::process::exit(2);
}
// Not an example of Gutenberg but is used to generate the theme and syntax dump
// used for syntax highlighting.
// Check README for more details
2017-03-20 08:30:50 +00:00
fn main() {
let mut args = env::args().skip(1);
match (args.next(), args.next(), args.next()) {
(Some(ref cmd), Some(ref package_dir), Some(ref packpath_newlines)) if cmd == "synpack" => {
2018-10-09 12:33:43 +00:00
let mut builder = SyntaxSetBuilder::new();
builder.add_plain_text_syntax();
builder.add_from_folder(package_dir, true).unwrap();
let ss = builder.build();
dump_to_file(&ss, packpath_newlines).unwrap();
2017-03-20 08:30:50 +00:00
2018-10-09 12:33:43 +00:00
for s in ss.syntaxes() {
if !s.file_extensions.is_empty() {
println!("- {} -> {:?}", s.name, s.file_extensions);
}
}
},
(Some(ref cmd), Some(ref theme_dir), Some(ref packpath)) if cmd == "themepack" => {
2017-03-20 08:30:50 +00:00
let ts = ThemeSet::load_from_folder(theme_dir).unwrap();
2017-03-22 11:59:49 +00:00
for path in ts.themes.keys() {
2017-03-20 08:30:50 +00:00
println!("{:?}", path);
}
dump_to_file(&ts, packpath).unwrap();
}
_ => usage_and_exit(),
}
}