Skip to content

Commit 68f8f1a

Browse files
authored
Merge pull request #55 from pattern-tech/fix/code-block
fix: update CodeBlock component to improve conditional rendering
2 parents de3b2de + 10ae7a7 commit 68f8f1a

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

components/code-block.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
'use client';
22

33
interface CodeBlockProps {
4-
node: any;
5-
inline: boolean;
6-
className: string;
7-
children: any;
4+
node?: any;
5+
className?: string;
6+
children?: any;
87
}
98

109
export function CodeBlock({
1110
node,
12-
inline,
1311
className,
1412
children,
1513
...props
1614
}: CodeBlockProps) {
17-
if (!inline) {
15+
if (node?.children[0]?.value?.endsWith('\n')) {
1816
return (
1917
<div className="not-prose flex flex-col">
2018
<pre

components/markdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Link from 'next/link';
22
import React, { memo } from 'react';
33
import ReactMarkdown, { type Components } from 'react-markdown';
44
import remarkGfm from 'remark-gfm';
5+
56
import { CodeBlock } from './code-block';
67

78
const components: Partial<Components> = {
8-
// @ts-expect-error
99
code: CodeBlock,
1010
pre: ({ children }) => <>{children}</>,
1111
ol: ({ node, children, ...props }) => {

0 commit comments

Comments
 (0)