fix: pass boolean and number values as a string in highlight function (#1512)

This commit is contained in:
Anton Kozachuk 2021-01-30 14:19:18 +02:00 committed by GitHub
parent 0dce880dce
commit c874a5942c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,11 +68,11 @@ export function mapLang(lang: string): string {
* @param lang highlight language
* @return highlighted source code as **html string**
*/
export function highlight(source: string, lang: string = DEFAULT_LANG): string {
export function highlight(source: string | number | boolean, lang: string = DEFAULT_LANG): string {
lang = lang.toLowerCase();
let grammar = Prism.languages[lang];
if (!grammar) {
grammar = Prism.languages[mapLang(lang)];
}
return Prism.highlight(source, grammar, lang);
return Prism.highlight(source.toString(), grammar, lang);
}