Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Code Snippet Comments Block for Svelte

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.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Let answers carry code people can read and copy, with this question and answers thread for Svelte with Ark 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.

Why is the preview a Collapsible?

It keeps the composer short once you have seen it work: the trigger always shows how many code blocks the draft holds, and the open panel has a fixed height so typing never moves the page. It starts open so the first thing you see is the feature.

How does it look on a phone?

The thread and the composer stack, code blocks scroll sideways inside their frame instead of widening the page, and the post button goes full width. The language tabs and the Copy button stay on one row.