Skip to content

Commit 58ae668

Browse files
committed
fix: crash on any backticks code block without lang specified
1 parent fc31145 commit 58ae668

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/services/__tests__/prism.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ describe('prism.js helpers', () => {
1616
test('highlight raw text should just return text', () => {
1717
expect(highlight('Hello world', 'clike')).toBe('Hello world');
1818
});
19+
20+
test('highlight should not throw with lang undefined', () => {
21+
expect(highlight('Hello world', undefined)).toBe('Hello world');
22+
});
1923
});

src/utils/highlight.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function mapLang(lang: string): string {
4242
* @param lang highlight language
4343
* @return highlighted souce code as **html string**
4444
*/
45-
export function highlight(source: string, lang: string): string {
45+
export function highlight(source: string, lang: string = DEFAULT_LANG): string {
4646
lang = lang.toLowerCase();
4747
let grammar = Prism.languages[lang];
4848
if (!grammar) {

0 commit comments

Comments
 (0)