Skip to content

fix: add syntax highlighting to blog code blocks#13

Merged
ajbozarth merged 2 commits into
generative-computing:mainfrom
ajbozarth:fix/md-code-block
Apr 17, 2026
Merged

fix: add syntax highlighting to blog code blocks#13
ajbozarth merged 2 commits into
generative-computing:mainfrom
ajbozarth:fix/md-code-block

Conversation

@ajbozarth

Copy link
Copy Markdown
Contributor

Adds rehype-highlight to the blog post renderer and imports the highlight.js GitHub theme (dark by default, light via prefers-color-scheme).

Previously, fenced code blocks in blog posts rendered as plain unstyled text.

Signed-off-by: Alex Bozarth <ajbozart@us.ibm.com>
@ajbozarth ajbozarth self-assigned this Apr 16, 2026
@ajbozarth
ajbozarth requested a review from a team as a code owner April 16, 2026 20:24
@ajbozarth
ajbozarth requested review from akihikokuroda and nrfulton and removed request for a team April 16, 2026 20:24
@ajbozarth ajbozarth added the bug Something isn't working label Apr 16, 2026
This was referenced Apr 16, 2026

@psschwei psschwei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Small, focused PR — the approach is correct. rehype-highlight in the rehype pipeline is the right integration for a statically-exported Next.js site. Three items to address before merging:

1. Add ignoreMissing: true to rehypeHighlight

If a blog author uses a fenced code block with an unrecognized language (e.g. ```mermaid, ```pseudocode), the build will fail. Since blog posts come from external contributors, this needs a safety net:

rehypePlugins={[rehypeSlug, [rehypeHighlight, { ignoreMissing: true }]]}

2. Conditional @import may not survive the Next.js build pipeline

The syntax @import 'github.css' (prefers-color-scheme: light) is valid modern CSS, but the bundler (PostCSS/lightningcss) may flatten it, causing the light theme to unconditionally override the dark theme for all users. Either:

  • Verify in the built output that the light-mode styles are wrapped in @media (prefers-color-scheme: light), or
  • Switch to importing only github-dark.css and inlining the light-mode color overrides inside the existing @media (prefers-color-scheme: light) block in globals.css (more robust, consistent with how the project already handles theming)

3. Add a defensive CSS reset for .prose pre code.hljs

highlight.js sets padding: 1em, display: block, and overflow-x: auto on pre code.hljs. These apply unchallenged by the existing .prose pre code rule and will cause double padding and layout changes. Add:

.prose pre code.hljs {
  background: none;
  padding: 0;
  display: initial;
  overflow-x: visible;
}

What's working well

  • Minimal diff, correct plugin ordering, dependencies already in package.json
  • Theme choice (github-dark / github) aligns with the project's dark-first convention and existing --code-bg: #0d1117

@psschwei psschwei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: Gemini reviewed the wrong PR ☹️

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>
@ajbozarth

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressing each item:

1. ignoreMissing: true — Fixed in 5a6bf30.

2. Conditional @import — Tested against the production build (npm run build && npx serve out) and verified the light theme applies correctly under prefers-color-scheme: light. The Next.js 16 / Turbopack pipeline preserves the media condition on the import, so no change needed here.

3. .prose pre code.hljs padding reset — The existing .prose pre code rule in globals.css already sets padding: 0 and background: none with higher specificity than .hljs, so there's no double-padding in practice. No change needed.

@ajbozarth
ajbozarth merged commit b0a3e96 into generative-computing:main Apr 17, 2026
6 checks passed
@ajbozarth
ajbozarth deleted the fix/md-code-block branch April 17, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants