Skip to content

Commit 33e70f1

Browse files
committed
Resolve warning when code block has no language
1 parent 3af0c49 commit 33e70f1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/markdown-to-react-loader.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ function processCodeBlock (code, lang) {
3232
// users can easily type in any language they want,
3333
// we don't want the app to blow up in case of bad input.
3434
try {
35-
require(`prismjs/components/prism-${lang}`);
36-
className = `language-${lang}`;
37-
highlighter = Prism.languages[lang];
35+
if (typeof lang === 'undefined') {
36+
className = '';
37+
highlighter = '';
38+
} else {
39+
require(`prismjs/components/prism-${lang}`);
40+
className = `language-${lang}`;
41+
highlighter = Prism.languages[lang];
42+
}
3843
} catch (e) {
39-
console.warn(`Could not find PrismJS language ${lang}`);
44+
console.warn(`Could not find PrismJS language ${lang}`, e);
4045
className = '';
4146
highlighter = '';
4247
}

test/all.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ test('Converts tables and table cells', () => {
5050
expectIO('io/table.md', 'io/table.js');
5151
});
5252

53-
test('It can render everything', () => {
53+
test('Can render everything', () => {
5454
expectIO('io/everything.md', 'io/everything.js');
5555
});

0 commit comments

Comments
 (0)