fix: don't load Prism if no language is specified for a code block
Some checks failed
Deploy Next.js application / deploy (push) Has been cancelled

This commit is contained in:
Dorian Niemiec 2024-09-22 07:02:19 +02:00
parent f408ed6bc8
commit 172eb25fe8

View file

@ -123,21 +123,23 @@ const customPortableTextComponents: PortableTextComponents = {
);
},
code: ({ value }) => {
const language = value.language || "javascript";
const language = value.language;
const grammar = Prism.languages[language];
if (!grammar) {
if (language && !grammar) {
console.error(`No grammar found for language: "${language}"`);
}
return (
<div className="relative my-8">
<pre
className={`language-${language} p-4 rounded-md overflow-x-auto text-sm`}
className={`${language ? "language-" + language + " " : ""}p-4 rounded-md overflow-x-auto text-sm`}
>
<code className={`language-${language}`}>{value.code}</code>
<code className={language ? "language-" + language : ""}>
{value.code}
</code>
</pre>
<PrismLoader />
{language ? <PrismLoader /> : ""}
<CopyButton code={value.code} />
</div>
);