mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-13 12:26:34 +03:00
fix: crash on any backticks code block without lang specified
This commit is contained in:
parent
fc31145b24
commit
58ae668f64
|
@ -16,4 +16,8 @@ describe('prism.js helpers', () => {
|
||||||
test('highlight raw text should just return text', () => {
|
test('highlight raw text should just return text', () => {
|
||||||
expect(highlight('Hello world', 'clike')).toBe('Hello world');
|
expect(highlight('Hello world', 'clike')).toBe('Hello world');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('highlight should not throw with lang undefined', () => {
|
||||||
|
expect(highlight('Hello world', undefined)).toBe('Hello world');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,7 +42,7 @@ export function mapLang(lang: string): string {
|
||||||
* @param lang highlight language
|
* @param lang highlight language
|
||||||
* @return highlighted souce code as **html string**
|
* @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();
|
lang = lang.toLowerCase();
|
||||||
let grammar = Prism.languages[lang];
|
let grammar = Prism.languages[lang];
|
||||||
if (!grammar) {
|
if (!grammar) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user