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
Some checks failed
Deploy Next.js application / deploy (push) Has been cancelled
This commit is contained in:
parent
f408ed6bc8
commit
172eb25fe8
1 changed files with 7 additions and 5 deletions
|
@ -123,21 +123,23 @@ const customPortableTextComponents: PortableTextComponents = {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
code: ({ value }) => {
|
code: ({ value }) => {
|
||||||
const language = value.language || "javascript";
|
const language = value.language;
|
||||||
const grammar = Prism.languages[language];
|
const grammar = Prism.languages[language];
|
||||||
|
|
||||||
if (!grammar) {
|
if (language && !grammar) {
|
||||||
console.error(`No grammar found for language: "${language}"`);
|
console.error(`No grammar found for language: "${language}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative my-8">
|
<div className="relative my-8">
|
||||||
<pre
|
<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>
|
</pre>
|
||||||
<PrismLoader />
|
{language ? <PrismLoader /> : ""}
|
||||||
<CopyButton code={value.code} />
|
<CopyButton code={value.code} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue