Skip to content

Commit

Permalink
fix: crash on any backticks code block without lang specified
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Aug 9, 2018
1 parent fc31145 commit 58ae668
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/services/__tests__/prism.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion src/utils/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 58ae668

Please sign in to comment.