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.

33 lines
903B

  1. #[macro_use]
  2. extern crate lazy_static;
  3. extern crate syntect;
  4. use syntect::dumps::from_binary;
  5. use syntect::parsing::SyntaxSet;
  6. use syntect::highlighting::{ThemeSet, Theme};
  7. use syntect::easy::HighlightLines;
  8. thread_local!{
  9. pub static SYNTAX_SET: SyntaxSet = {
  10. let mut ss: SyntaxSet = from_binary(include_bytes!("../../../sublime_syntaxes/newlines.packdump"));
  11. ss.link_syntaxes();
  12. ss
  13. };
  14. }
  15. lazy_static!{
  16. pub static ref THEME_SET: ThemeSet = from_binary(include_bytes!("../../../sublime_themes/all.themedump"));
  17. }
  18. pub fn get_highlighter<'a>(theme: &'a Theme, info: &str) -> HighlightLines<'a> {
  19. SYNTAX_SET.with(|ss| {
  20. let syntax = info
  21. .split(' ')
  22. .next()
  23. .and_then(|lang| ss.find_syntax_by_token(lang))
  24. .unwrap_or_else(|| ss.find_syntax_plain_text());
  25. HighlightLines::new(syntax, theme)
  26. })
  27. }