Skip to content

Commit b0a3e96

Browse files
authored
fix: add syntax highlighting to blog code blocks (#13)
* fix: add syntax highlighting to blog code blocks Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com> * fix: guard rehype-highlight against unrecognized language tags Passes `ignoreMissing: true` so fenced code blocks with unrecognized language identifiers (e.g. mermaid, pseudocode) do not throw during build. Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com> --------- Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
1 parent ac7dd6f commit b0a3e96

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/app/blogs/[slug]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { notFound } from 'next/navigation';
44
import ReactMarkdown from 'react-markdown';
55
import remarkGfm from 'remark-gfm';
66
import rehypeSlug from 'rehype-slug';
7+
import rehypeHighlight from 'rehype-highlight';
78
import { getBlog, getAllBlogSlugs } from '@/lib/blogs';
89
import { siteConfig } from '@/config/site';
910

@@ -79,7 +80,7 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug:
7980
<div className="prose">
8081
<ReactMarkdown
8182
remarkPlugins={[remarkGfm]}
82-
rehypePlugins={[rehypeSlug]}
83+
rehypePlugins={[rehypeSlug, [rehypeHighlight, { ignoreMissing: true }]]}
8384
>
8485
{blog.content}
8586
</ReactMarkdown>

src/app/globals.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* IBM Plex + developer theme — light/dark via prefers-color-scheme */
22
/* Fonts loaded via next/font in layout.tsx — CSS vars set on <body> */
33

4+
@import 'highlight.js/styles/github-dark.css';
5+
@import 'highlight.js/styles/github.css' (prefers-color-scheme: light);
6+
47
*, *::before, *::after {
58
box-sizing: border-box;
69
margin: 0;

0 commit comments

Comments
 (0)