fix: crash on any backticks code block without lang specified

This commit is contained in:
Roman Hotsiy 2018-08-09 08:44:01 +03:00
parent fc31145b24
commit 58ae668f64
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 5 additions and 1 deletions

View File

@ -16,4 +16,8 @@ describe('prism.js helpers', () => {
test('highlight raw text should just return text', () => {
expect(highlight('Hello world', 'clike')).toBe('Hello world');
});
test('highlight should not throw with lang undefined', () => {
expect(highlight('Hello world', undefined)).toBe('Hello world');
});
});

View File

@ -42,7 +42,7 @@ export function mapLang(lang: string): string {
* @param lang highlight language
* @return highlighted souce code as **html string**
*/
export function highlight(source: string, lang: string): string {
export function highlight(source: string, lang: string = DEFAULT_LANG): string {
lang = lang.toLowerCase();
let grammar = Prism.languages[lang];
if (!grammar) {