Support specifying syntax highlighting language
The Gerrit API only returns the content_type, which is then used to derive the programming language to pass to highlight.js. However, for different users of gr-diff, it is more convenient to be able to specify the programming language directly. This change supports that, and falls back to use the MIME type when the language is not specified, so this should keep working as it used to for everyone not specifying the language explicitly. Change-Id: I20d13af6319e099544411665f4a23a5ff150e443
This commit is contained in:
@@ -191,6 +191,13 @@
|
||||
}
|
||||
},
|
||||
|
||||
_getLanguage(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 diffFileMetaInfo.language ||
|
||||
LANGUAGE_MAP[diffFileMetaInfo.content_type];
|
||||
},
|
||||
|
||||
/**
|
||||
* Start processing symtax for the loaded diff and notify layer listeners
|
||||
* as syntax info comes online.
|
||||
@@ -208,10 +215,10 @@
|
||||
this.cancel();
|
||||
|
||||
if (this.diff.meta_a) {
|
||||
this._baseLanguage = LANGUAGE_MAP[this.diff.meta_a.content_type];
|
||||
this._baseLanguage = this._getLanguage(this.diff.meta_a);
|
||||
}
|
||||
if (this.diff.meta_b) {
|
||||
this._revisionLanguage = LANGUAGE_MAP[this.diff.meta_b.content_type];
|
||||
this._revisionLanguage = this._getLanguage(this.diff.meta_b);
|
||||
}
|
||||
if (!this._baseLanguage && !this._revisionLanguage) {
|
||||
return Promise.resolve();
|
||||
|
||||
Reference in New Issue
Block a user