@@ -23,6 +23,17 @@ pub struct HighlightingAssets {
2323 fallback_theme: Option<&'static str>,
2424}
2525
26+const IGNORED_SUFFIXES: [&str; 10] = [
27+ // Editor etc backups
28+ "~", ".bak", ".old", ".orig",
29+ // Debian and derivatives apt/dpkg backups
30+ ".dpkg-dist", ".dpkg-old",
31+ // Red Hat and derivatives rpm backups
32+ ".rpmnew", ".rpmorig", ".rpmsave",
33+ // Build system input/template files
34+ ".in",
35+];
36+
2637impl HighlightingAssets {
2738 pub fn default_theme() -> &'static str {
2839 "Monokai Extended"
@@ -273,12 +284,26 @@ impl HighlightingAssets {
273284 self.syntax_set
274285 .find_syntax_by_extension(file_name.to_str().unwrap_or_default())
275286 .or_else(|| {
287+ let file_path = Path::new(file_name);
276288 self.syntax_set.find_syntax_by_extension(
277− Path::new(file_name)
289+ file_path
278290 .extension()
279291 .and_then(|x| x.to_str())
280292 .unwrap_or_default(),
281− )
293+ ).or_else(|| {
294+ let file_str = file_path.to_str().unwrap_or_default();
295+ for suffix in IGNORED_SUFFIXES.iter() {
296+ if file_str.ends_with(suffix) {
297+ return self.get_extension_syntax(
298+ OsStr::new(
299+ file_str
300+ .strip_suffix(suffix)
301+ .unwrap_or_default()
302+ ));
303+ }
304+ }
305+ None
306+ })
282307 })
283308 }
284309