From 659ab2d4a03ff02e0e3cfd6d396def8d12b4451a Mon Sep 17 00:00:00 2001 From: Mengqi Pei Date: Wed, 3 Apr 2024 14:32:17 +0800 Subject: [PATCH] Add style for inline code --- contentlayer.config.ts | 13 ------------- src/app/_components/code-block.tsx | 7 ++++++- src/app/_components/markdown-post.tsx | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/contentlayer.config.ts b/contentlayer.config.ts index 2c86b48..d38fbfa 100644 --- a/contentlayer.config.ts +++ b/contentlayer.config.ts @@ -88,19 +88,6 @@ export default makeSource({ [rehypeAutolinkHeadings, 'after'], [rehypePrettyCode, { theme: 'solarized-light', - // onVisitLine(node: { children: string | any[] }) { - // // Prevent lines from collapsing in `display: grid` mode, and allow empty - // // lines to be copy/pasted - // if (node.children.length === 0) { - // node.children = [{ type: "text", value: " " }] - // } - // }, - // onVisitHighlightedLine(node: { properties: { className: string[] } }) { - // node.properties.className.push("line--highlighted") - // }, - // onVisitHighlightedWord(node: { properties: { className: string[] } }) { - // node.properties.className = ["word--highlighted"] - // }, }], postProcess ] diff --git a/src/app/_components/code-block.tsx b/src/app/_components/code-block.tsx index 7b9381d..6bdf21b 100644 --- a/src/app/_components/code-block.tsx +++ b/src/app/_components/code-block.tsx @@ -2,16 +2,21 @@ import clsx from "clsx"; import ClipboardCopy from "./clipboard-copy"; +import { ReactElement } from "react"; interface CodeBlockProps extends React.HTMLAttributes{ raw?: string } const CodeBlock: React.FC = ({ className, children, raw, ...props }: CodeBlockProps) => { + children = children as ReactElement; + if (!children || children.type !== 'code') return null; + + children.props.className = children.props.className.replace(/ bg-\w+/, ''); return ( <>
-
+                
                     {children}
                     
                 
diff --git a/src/app/_components/markdown-post.tsx b/src/app/_components/markdown-post.tsx index c51ba75..280792e 100644 --- a/src/app/_components/markdown-post.tsx +++ b/src/app/_components/markdown-post.tsx @@ -13,7 +13,7 @@ const components: MDXComponents = { ul: ({ children }) =>
    {children}
, li: ({ children }) =>
  • {children}
  • , pre: CodeBlock, - code: ({ children }) => {children}, + code: ({ children }) => {children}, lead: ({ children }) =>

    {children}

    , a: ({ children, href }) => ( {children}