shadcn.io is not affiliated with official shadcn/ui
Code Snippet Comments Block for Radix UI
A question and answers thread whose answers carry code: the same fix in TypeScript and Python tabs with numbered lines and Copy, and a composer that reads fenced code blocks into a collapsible preview.
Installation
Overview
Let answers carry code people can read and copy, with this question and answers thread for React with Radix UI. A question on Fencely (retry a request with a growing wait) has one answer that holds the same fix in TypeScript and Python in Tabs. Each code block has numbered lines in an ordered list, token weights in a single colour (keywords semibold, comments muted, strings softer, drawn from a typed regular expression) and a Copy Button that says "Copied". The composer reads fenced blocks (three backticks and a language) as you type and shows them in a preview inside a Collapsible, and "Add a code block" puts a fence at the cursor with the cursor between the fences. A small typed parser draws plain elements, so nothing is injected as HTML, and one Shine Button posts the answer into the thread, code blocks and all. Built from Tabs, Copy Button, Textarea, Collapsible, Badge, Field, Avatar, Shine Button and Guides. For developer Q and A, support forums and docs comments.
FAQ
How do I add my own code and languages?
Edit LANGS (a label, a value and the code for each tab) and the TS_CODE and PY_CODE lines at the top of the file. Code is stored as arrays of lines joined with a newline, so editing a line never needs escaping. Keywords are listed once in TOKEN and KEYWORD; add a word to both to give it weight. The colouring is a light touch on purpose: for full highlighting, swap bitsOf for your highlighter's tokens.
What stays local, and how do I make it real?
Everything. Posting adds the answer to a list in the page and the status line says nothing was sent. Copy writes to the real clipboard when the browser allows it. To make it real, send the markdown text from post to your API and store it as text, and sanitize on the server: the parser here only builds React elements.
How are fenced blocks read?
A line of three backticks with an optional language opens a block and the next line of three backticks closes it; an unclosed fence runs to the end of the text. The language shows in a small badge, and the block gets numbered lines and its own Copy button. Anything else is plain paragraphs with inline code.
Is it accessible?
Each code block is a labelled region you can reach with Tab and scroll sideways with the arrow keys, line numbers are hidden from screen readers so only the code is read, and Copy is named for the language it copies. The language tabs are a labelled tablist. Copy announces "Copied" politely.