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.

42 lines
1.4KB

  1. use syntect::dumps::from_binary;
  2. use syntect::parsing::SyntaxSet;
  3. use syntect::highlighting::ThemeSet;
  4. use syntect::easy::HighlightLines;
  5. use Config;
  6. lazy_static! {
  7. pub static ref SYNTAX_SET: SyntaxSet = {
  8. let ss: SyntaxSet = from_binary(include_bytes!("../../../sublime_syntaxes/newlines.packdump"));
  9. ss
  10. };
  11. pub static ref THEME_SET: ThemeSet = from_binary(include_bytes!("../../../sublime_themes/all.themedump"));
  12. }
  13. /// Returns the highlighter and whether it was found in the extra or not
  14. pub fn get_highlighter<'a>(info: &str, config: &Config) -> (HighlightLines<'a>, bool) {
  15. let theme = &THEME_SET.themes[&config.highlight_theme];
  16. let mut in_extra = false;
  17. if let Some(ref lang) = info.split(' ').next() {
  18. let syntax = SYNTAX_SET.find_syntax_by_token(lang)
  19. .or_else(|| {
  20. if let Some(ref extra) = config.extra_syntax_set {
  21. let s = extra.find_syntax_by_token(lang);
  22. if s.is_some() {
  23. in_extra = true;
  24. }
  25. s
  26. } else {
  27. None
  28. }
  29. })
  30. .unwrap_or_else(|| SYNTAX_SET.find_syntax_plain_text());
  31. (HighlightLines::new(syntax, theme), in_extra)
  32. } else {
  33. (HighlightLines::new(SYNTAX_SET.find_syntax_plain_text(), theme), false)
  34. }
  35. }