|
@@ -1,11 +1,12 @@
|
|
|
-import { ReactNode } from 'react';
|
|
|
|
|
|
|
+import type { ReactNode } from 'react';
|
|
|
|
|
|
|
|
-import type { CodeComponent } from 'react-markdown/lib/ast-to-react';
|
|
|
|
|
|
|
+import type { CodeComponent, CodeProps } from 'react-markdown/lib/ast-to-react';
|
|
|
import { PrismAsyncLight } from 'react-syntax-highlighter';
|
|
import { PrismAsyncLight } from 'react-syntax-highlighter';
|
|
|
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
|
|
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
|
|
|
|
|
|
|
|
import styles from './CodeBlock.module.scss';
|
|
import styles from './CodeBlock.module.scss';
|
|
|
|
|
|
|
|
|
|
+const codeHighlightedClass = styles['code-highlighted'];
|
|
|
|
|
|
|
|
// remove font-family
|
|
// remove font-family
|
|
|
Object.entries<object>(oneDark).forEach(([key, value]) => {
|
|
Object.entries<object>(oneDark).forEach(([key, value]) => {
|
|
@@ -49,7 +50,7 @@ function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactN
|
|
|
const isSimpleString = Array.isArray(children) && children.length === 1 && typeof children[0] === 'string';
|
|
const isSimpleString = Array.isArray(children) && children.length === 1 && typeof children[0] === 'string';
|
|
|
if (!isSimpleString) {
|
|
if (!isSimpleString) {
|
|
|
return (
|
|
return (
|
|
|
- <div className="code-highlighted" style={oneDark['pre[class*="language-"]']}>
|
|
|
|
|
|
|
+ <div className={codeHighlightedClass} style={oneDark['pre[class*="language-"]']}>
|
|
|
<code className={`language-${lang}`} style={oneDark['code[class*="language-"]']}>
|
|
<code className={`language-${lang}`} style={oneDark['code[class*="language-"]']}>
|
|
|
{children}
|
|
{children}
|
|
|
</code>
|
|
</code>
|
|
@@ -59,7 +60,7 @@ function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactN
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<PrismAsyncLight
|
|
<PrismAsyncLight
|
|
|
- className="code-highlighted"
|
|
|
|
|
|
|
+ className={codeHighlightedClass}
|
|
|
PreTag="div"
|
|
PreTag="div"
|
|
|
style={oneDark}
|
|
style={oneDark}
|
|
|
language={lang}
|
|
language={lang}
|
|
@@ -69,7 +70,7 @@ function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactN
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export const CodeBlock: CodeComponent = ({ inline, className, children }) => {
|
|
|
|
|
|
|
+export const CodeBlock: CodeComponent = ({ inline, className, children }: CodeProps) => {
|
|
|
|
|
|
|
|
if (inline) {
|
|
if (inline) {
|
|
|
return <code className={`code-inline ${className ?? ''}`}>{children}</code>;
|
|
return <code className={`code-inline ${className ?? ''}`}>{children}</code>;
|