|
|
@@ -14,11 +14,11 @@ Object.entries<object>(oneDark).forEach(([key, value]) => {
|
|
|
|
|
|
|
|
|
type InlineCodeBlockProps = {
|
|
|
- children: ReactNode,
|
|
|
- className?: string,
|
|
|
+ children: ReactNode,
|
|
|
+ className?: string,
|
|
|
}
|
|
|
|
|
|
-export const InlineCodeBlockSubstance = (props: InlineCodeBlockProps): JSX.Element => {
|
|
|
+const InlineCodeBlockSubstance = (props: InlineCodeBlockProps): JSX.Element => {
|
|
|
const { children, className, ...rest } = props;
|
|
|
return <code className={`code-inline ${className ?? ''}`} {...rest}>{children}</code>;
|
|
|
};
|
|
|
@@ -50,8 +50,22 @@ function extractChildrenToIgnoreReactNode(children: ReactNode): ReactNode {
|
|
|
}
|
|
|
|
|
|
function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactNode }): JSX.Element {
|
|
|
- // SIMPLIFIED: Now that this function is only for block-level code,
|
|
|
- // the conditional check for isSimpleString is no longer necessary.
|
|
|
+ // return alternative element
|
|
|
+ // in order to fix "CodeBlock string is be [object Object] if searched"
|
|
|
+ // see: https://github.com/weseek/growi/pull/7484
|
|
|
+ //
|
|
|
+ // Note: You can also remove this code if the user requests to see the code highlighted in Prism as-is.
|
|
|
+
|
|
|
+ const isSimpleString = typeof children === 'string' || (Array.isArray(children) && children.length === 1 && typeof children[0] === 'string');
|
|
|
+ if (!isSimpleString) {
|
|
|
+ return (
|
|
|
+ <div style={oneDark['pre[class*="language-"]']}>
|
|
|
+ <code className={`language-${lang}`} style={oneDark['code[class*="language-"]']}>
|
|
|
+ {children}
|
|
|
+ </code>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<PrismAsyncLight
|
|
|
@@ -65,13 +79,18 @@ function CodeBlockSubstance({ lang, children }: { lang: string, children: ReactN
|
|
|
}
|
|
|
|
|
|
type CodeBlockProps = {
|
|
|
- children: ReactNode,
|
|
|
- className?: string,
|
|
|
+ children: ReactNode,
|
|
|
+ className?: string,
|
|
|
+ inline?: true,
|
|
|
}
|
|
|
|
|
|
export const CodeBlock = (props: CodeBlockProps): JSX.Element => {
|
|
|
+
|
|
|
// TODO: set border according to the value of 'customize:highlightJsStyleBorder'
|
|
|
- const { className, children } = props;
|
|
|
+ const { className, children, inline } = props;
|
|
|
+ if (inline) {
|
|
|
+ return <InlineCodeBlockSubstance className={`code-inline ${className ?? ''}`}>{children}</InlineCodeBlockSubstance>;
|
|
|
+ }
|
|
|
|
|
|
const match = /language-(\w+)(:?.+)?/.exec(className || '');
|
|
|
const lang = match && match[1] ? match[1] : '';
|