Skip to content

Commit 0e81a0f

Browse files
committed
feat: markdown rendered with custom theme
1 parent 9674bf7 commit 0e81a0f

File tree

4 files changed

+417
-2
lines changed

4 files changed

+417
-2
lines changed

src/index.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ code {
3939
}
4040

4141
/* Styling for inline code blocks */
42+
.prose code.undefined:not(pre > code) {
43+
background-color: #242424;
44+
}
45+
4246
.prose code:not(pre > code) {
43-
background-color: #242424; /* gray-600 */ /* Changed background color */
4447
color: #f87171; /* primary-400 - Reverted color */
4548
padding: 0.2em 0.4em;
4649
border-radius: 0.25rem;

src/pages/BlogPostPage.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useState, useEffect, useRef } from 'react';
22
import { useParams, Link } from 'react-router-dom';
33
import ReactMarkdown from 'react-markdown';
4+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
5+
import { customTheme } from '../utils/customTheme';
46
import PostMetadata from '../components/PostMetadata';
57
import { ArrowLeftIcon, ArrowSquareOutIcon } from '@phosphor-icons/react';
68

@@ -13,6 +15,27 @@ const LinkRenderer = ({ href, children }) => {
1315
);
1416
};
1517

18+
19+
20+
const CodeBlock = ({ node, inline, className, children, ...props }) => {
21+
const match = /language-(\w+)/.exec(className || '');
22+
return !inline && match ? (
23+
<SyntaxHighlighter
24+
style={customTheme}
25+
language={match[1]}
26+
PreTag="div"
27+
{...props}
28+
codeTagProps={{ style: { fontFamily: "'JetBrains Mono', monospace" } }}
29+
>
30+
{String(children).replace(/\n$/, '')}
31+
</SyntaxHighlighter>
32+
) : (
33+
<code className={`${className} font-mono bg-gray-800`} {...props}>
34+
{children}
35+
</code>
36+
);
37+
};
38+
1639
const BlogPostPage = () => {
1740
const { slug } = useParams();
1841
const [post, setPost] = useState(null);
@@ -121,7 +144,7 @@ const BlogPostPage = () => {
121144
<ArrowLeftIcon size={24} /> Back to Home
122145
</Link>
123146
<div ref={contentRef} className="prose prose-xl prose-dark max-w-none">
124-
<ReactMarkdown components={{ a: LinkRenderer }}>{post.body}</ReactMarkdown>
147+
<ReactMarkdown components={{ a: LinkRenderer, code: CodeBlock }}>{post.body}</ReactMarkdown>
125148
</div>
126149
</div>
127150
<div className="hidden lg:block">

0 commit comments

Comments
 (0)