You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate_sublime.rs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //! This program is mainly intended for generating the dumps that are compiled in to
  2. //! syntect, not as a helpful example for beginners.
  3. //! Although it is a valid example for serializing syntaxes, you probably won't need
  4. //! to do this yourself unless you want to cache your own compiled grammars.
  5. extern crate syntect;
  6. use syntect::parsing::SyntaxSetBuilder;
  7. use syntect::highlighting::ThemeSet;
  8. use syntect::dumps::*;
  9. use std::env;
  10. fn usage_and_exit() -> ! {
  11. println!("USAGE: cargo run --example generate_sublime synpack source-dir newlines.packdump nonewlines.packdump\n
  12. cargo run --example generate_sublime themepack source-dir themepack.themedump");
  13. ::std::process::exit(2);
  14. }
  15. // Not an example of zola but is used to generate the theme and syntax dump
  16. // used for syntax highlighting.
  17. // Check README for more details
  18. fn main() {
  19. let mut args = env::args().skip(1);
  20. match (args.next(), args.next(), args.next()) {
  21. (Some(ref cmd), Some(ref package_dir), Some(ref packpath_newlines)) if cmd == "synpack" => {
  22. let mut builder = SyntaxSetBuilder::new();
  23. builder.add_plain_text_syntax();
  24. builder.add_from_folder(package_dir, true).unwrap();
  25. let ss = builder.build();
  26. dump_to_file(&ss, packpath_newlines).unwrap();
  27. for s in ss.syntaxes() {
  28. if !s.file_extensions.is_empty() {
  29. println!("- {} -> {:?}", s.name, s.file_extensions);
  30. }
  31. }
  32. },
  33. (Some(ref cmd), Some(ref theme_dir), Some(ref packpath)) if cmd == "themepack" => {
  34. let ts = ThemeSet::load_from_folder(theme_dir).unwrap();
  35. for path in ts.themes.keys() {
  36. println!("{:?}", path);
  37. }
  38. dump_to_file(&ts, packpath).unwrap();
  39. }
  40. _ => usage_and_exit(),
  41. }
  42. }