Skip to content

Commit 7fa6c02

Browse files
Add syntax highlighting to code blocks in devjourney component; update styles for improved readability
1 parent c6ca109 commit 7fa6c02

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

app/src/components/devjourney/devjourney.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { usePathname, useRouter } from "next/navigation";
55
import djStyles from "./devjourney.module.css";
66
import { BsFileEarmark, BsFolder, BsGithub } from "react-icons/bs";
77
import { marked } from "marked";
8+
import hljs from "highlight.js";
9+
import "highlight.js/styles/github-dark.css"; // Import your preferred style
810

911
const Repository = () => {
1012
const [data, setData] = useState([]);
@@ -102,6 +104,12 @@ const Repository = () => {
102104
if (pathname) fetchData();
103105
}, [pathname]);
104106

107+
useEffect(() => {
108+
if (fileContent?.content) {
109+
hljs.highlightAll(); // Apply syntax highlighting to code blocks
110+
}
111+
}, [fileContent]);
112+
105113
const handleItemClick = (item) => {
106114
const newPath = `/devjourney/${item.path}`;
107115
router.push(newPath);
@@ -110,7 +118,7 @@ const Repository = () => {
110118
const renderDirMap = () => {
111119
if (loading) return <p>Loading...</p>;
112120
if (error) return <p>Error: {error}</p>;
113-
if (data.length === 0) return null; // Hide if empty
121+
if (data.length === 0) return null;
114122

115123
return (
116124
<ul className={djStyles.dirMapContainer}>
@@ -126,25 +134,25 @@ const Repository = () => {
126134
);
127135
};
128136

129-
130137
const renderContent = () => {
131138
if (!fileContent) return null;
132139

133140
return (
134141
<div className={djStyles.contentContainer}>
135142
<h2 className={djStyles.fileName}>{fileContent.name}</h2>
136143
{fileContent.name.endsWith(".md") ? (
137-
// Render markdown content
138-
<div className={djStyles.markdownContent}
144+
<div
145+
className={djStyles.markdownContent}
139146
dangerouslySetInnerHTML={{ __html: marked(fileContent.content) }}
140147
/>
141148
) : (
142-
// Render plain text content
143-
<pre className={djStyles.fileContent}>
144-
{fileContent.content}
149+
< pre className="hljs">
150+
{/* Removed djStyles.fileContent */}
151+
<code>{fileContent.content}</code>
145152
</pre>
146-
)}
147-
</div>
153+
)
154+
}
155+
</div >
148156
);
149157
};
150158

@@ -160,25 +168,15 @@ const Repository = () => {
160168

161169
return (
162170
<div key={path} className={djStyles.breadcrumbHome}>
163-
<button
164-
165-
onClick={() => router.push(path)}
166-
>
167-
{decodedSegment}
168-
</button>
171+
<button onClick={() => router.push(path)}>{decodedSegment}</button>
169172
{index < pathSegments.length - 1 && " / "}
170173
</div>
171174
);
172175
});
173176

174177
return (
175-
<div className={djStyles.breadcrumbContainer} id='breadcrumb'>
176-
<button
177-
178-
onClick={() => router.push("/devjourney")}
179-
>
180-
Home
181-
</button>
178+
<div className={djStyles.breadcrumbContainer} id="breadcrumb">
179+
<button onClick={() => router.push("/devjourney")}>Home</button>
182180
{breadcrumbItems.length > 0 && " / "}
183181
{breadcrumbItems}
184182
</div>
@@ -200,12 +198,11 @@ const Repository = () => {
200198
};
201199

202200
return (
203-
<div className={djStyles.devjourneyContainer} id='main'>
201+
<div className={djStyles.devjourneyContainer} id="main">
204202
{renderBreadcrumb()}
205203
{renderGitHubButton()}
206204
{renderContent()}
207205
{renderDirMap()}
208-
209206
</div>
210207
);
211208
};

app/src/components/devjourney/devjourney.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
margin: var(--margin-medium) 0;
8383
padding: var(--padding-medium);
8484
border-radius: var(--border-radius-medium);
85-
background-color: var(--card-background-color);
85+
background-color: rgb(0 0 0 / 70%);
8686
backdrop-filter: blur(15px);
8787
font-size: 18px;
8888
}

package-lock.json

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
"discord.js": "^14.16.3",
3131
"dotenv": "^16.4.5",
3232
"express": "^4.21.2",
33+
"highlight.js": "^11.11.1",
3334
"morgan": "^1.10.0",
3435
"querystring": "^0.2.1",
3536
"winston": "^3.16.0"
3637
}
37-
}
38+
}

0 commit comments

Comments
 (0)