From a76aba976de1a1e46c5aeb8772f3f2d58c7efda4 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Thu, 2 Jul 2020 23:02:43 +0100 Subject: [PATCH 3/6] 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 0c3bb40ce4..ace253da30 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 @@ -109,6 +109,10 @@ const LANGUAGE_MAP = new Map([ ]); const ASYNC_DELAY = 10; +const FILENAME_OVERRIDES = new Map([ + ['rules.pl', 'prolog'], +]); + const CLASS_SAFELIST = new Set([ 'gr-diff gr-syntax gr-syntax-attr', 'gr-diff gr-syntax gr-syntax-attribute', @@ -258,10 +262,17 @@ export class GrSyntaxLayer } } + _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