Do not syntax highlight for unknown languages
highlight.js supports ~180 languages, but alas, developers have come up with even more. Since we do not control the languages developers use, check that first instead of crashing when an unsupported language is used. Change-Id: Id8dbd11d63affe17eb009cd90a7d9e097b164ad4
This commit is contained in:
@@ -349,7 +349,8 @@
|
|||||||
// To store the result of the syntax highlighter.
|
// To store the result of the syntax highlighter.
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
if (this._baseLanguage && baseLine !== undefined) {
|
if (this._baseLanguage && baseLine !== undefined &&
|
||||||
|
this._hljs.getLanguage(this._baseLanguage)) {
|
||||||
baseLine = this._workaround(this._baseLanguage, baseLine);
|
baseLine = this._workaround(this._baseLanguage, baseLine);
|
||||||
result = this._hljs.highlight(this._baseLanguage, baseLine, true,
|
result = this._hljs.highlight(this._baseLanguage, baseLine, true,
|
||||||
state.baseContext);
|
state.baseContext);
|
||||||
@@ -357,7 +358,8 @@
|
|||||||
state.baseContext = result.top;
|
state.baseContext = result.top;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._revisionLanguage && revisionLine !== undefined) {
|
if (this._revisionLanguage && revisionLine !== undefined &&
|
||||||
|
this._hljs.getLanguage(this._revisionLanguage)) {
|
||||||
revisionLine = this._workaround(this._revisionLanguage, revisionLine);
|
revisionLine = this._workaround(this._revisionLanguage, revisionLine);
|
||||||
result = this._hljs.highlight(this._revisionLanguage, revisionLine,
|
result = this._hljs.highlight(this._revisionLanguage, revisionLine,
|
||||||
true, state.revisionContext);
|
true, state.revisionContext);
|
||||||
|
@@ -50,6 +50,11 @@ limitations under the License.
|
|||||||
top: state === undefined ? 1 : state + 1,
|
top: state === undefined ? 1 : state + 1,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
// Return something truthy because this method is used to check if the
|
||||||
|
// language is supported.
|
||||||
|
getLanguage(s) {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user