Skip to content
Viewership Inquire
Astro UI

Code Block.

Line-numbered code listing with copy, or a unified diff.

ContentComponentNo dependencies Beautiful UI, MIT

.md
draft.ts
export async function draftPost() {
const brief = await getBrief("spring-trails");
const data = await ga4.fetch({ brief });
await voice.apply(data, { tone: "direct" });
if (!data.approved) return null;
return data.summary;
}

Install

  1. Import the foundation once

    foundation.css holds the tokens every component reads.

    Layout.astro
    ---
    // src/layouts/Layout.astro
    import "../styles/foundation.css";
    ---
  2. Copy the 2 files

    Paste into src/components/viewership/code-block/

  3. Use it

    Page.astro
    ---
    import CodeBlock from "../components/viewership/code-block/CodeBlock.astro";
    ---
    
    <CodeBlock />

Props 8

PropTypeDefaultDescription
variant "code" | "diff" "code" Code listing or unified diff.
code string · Source text for the code view.
lines string[] · Alternative to `code`: one string per line.
language "ts" | "js" | "json" | "text" · Highlighting hint. Inferred from `filename`.
diff DiffRow[] | { before: string; after: string } · Diff rows, or two texts diffed at build time.
filename string "index.ts" Shown in the header.
copyText string · Clipboard text. Defaults to the listing.
labels { copy?, copied?, copiedAnnouncement? } · Copy button and screen reader text.

Source 2 files

Ported from Beautiful UI, MIT. Notices.