Skip to content

feat(components/codeblock): a reusable component for displaying syntax-highlighted code blocks #7470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gsvprharsha
Copy link

Summary

This PR adds a new CodeBlock component to the UI registry. It uses Shiki for syntax highlighting.

The component supports props like:

  • lang: the code language
  • maxHeight / maxWidth: for scrollable code areas
  • textSize: to adjust font size

Changes

  • Added the component at ui/codeblock.tsx
  • Added example usage at example/codeblock.tsx
  • Added registry metadata
  • Integrated shiki and hast-util-to-jsx-runtime

Example

<CodeBlock lang="js" maxHeight={300} maxWidth={300} textSize={14}>
  {`function greet() {
  console.log("Hello, world!")
}

greet()`}
</CodeBlock>

Features

  • Supports many programming languages from Shiki, including popular ones like JavaScript, TypeScript, and Python.
  • Offers customizable themes from Shiki’s built-in collection, allowing light and dark mode highlighting.
  • Provides props such as lang (language), textSize (font size), and maxHeight / maxWidth for scrollable code blocks.
  • Follows shadcn design principles.

Preview

A preview of the CodeBlock component showing syntax-highlighted code with customizable size and language support.

CodeBlock Preview

Copy link

vercel bot commented May 26, 2025

@wolfosek is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants