about summary refs log tree commit diff
path: root/third_party/gerrit/0003-Syntax-highlight-rules.pl.patch
blob: 096057f1ad4f02d8155b5248dcc45787cf36ae1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From 7c2e72527d177fd26505821e6297e6aa270a4f96 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 2 Jul 2020 23:02:43 +0100
Subject: [PATCH 3/7] Syntax highlight rules.pl

---
 .../diff/gr-syntax-layer/gr-syntax-layer.ts         | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.ts b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.ts
index 2762ccc625..ebb5d9dad9 100644
--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.ts
+++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.ts
@@ -103,6 +103,10 @@ const LANGUAGE_MAP = new Map<string, string>([
 ]);
 const ASYNC_DELAY = 10;
 
+const FILENAME_OVERRIDES = new Map<string, string>([
+  ['rules.pl', 'prolog'],
+]);
+
 const CLASS_SAFELIST = new Set<string>([
   'gr-diff gr-syntax gr-syntax-attr',
   'gr-diff gr-syntax gr-syntax-attribute',
@@ -241,10 +245,17 @@ export class GrSyntaxLayer implements DiffLayer {
     }
   }
 
+  _basename(filename: string): string {
+    const pieces = filename.split(/\//);
+    return pieces[pieces.length-1];
+  }
+
   _getLanguage(metaInfo: DiffFileMetaInfo) {
     // The Gerrit API provides only content-type, but for other users of
     // gr-diff it may be more convenient to specify the language directly.
-    return metaInfo.language ?? LANGUAGE_MAP.get(metaInfo.content_type);
+    return metaInfo.language ?? 
+        FILENAME_OVERRIDES.get(this._basename(metaInfo.name)) ??
+        LANGUAGE_MAP.get(metaInfo.content_type);
   }
 
   /**
-- 
2.29.2