Skip to content

ComponentsFormatting

SourceSource

Typeset

Styles the HTML a markdown renderer emits — CommonMark and GFM — with three variables: size, leading and flow.

Rendered markdown is the one thing a component library cannot style with components: what arrives is whatever the renderer emitted. Typeset is a wrapper and two class names — the rules are the stylesheet add typeset appends, and nothing inside needs a class of its own.

The builder tunes the three variables live; the guide explains what each one does.

import { Typeset } from "@/registry/bases/newt/ui/typeset"

/*
 * What a CommonMark + GFM renderer (remark-gfm, markdown-it, marked) emits for
 * a typical release note, element for element: Typeset never sees the source,
 * only the markup a renderer produced from it, and none of it carries a class.
 */
export default function TypesetDemo() {
  return (
    <Typeset as="article" preset="docs" measure>
      <h1>Release 2.4.0</h1>
      <p>
        Threads can now be started from the composer, and an archived one
        reopens on the first new message. The <code>threads</code> table gained
        a <strong>parent id</strong> for private threads, which <em>fixes</em>{" "}
        the list that <del>dropped them</del> lost them after a restart
        <sup>
          <a href="#typeset-demo-react-fn-1" id="typeset-demo-react-ref-1">
            1
          </a>
        </sup>
        . See <a href="#typeset-demo">the migration guide</a> for the backfill.
      </p>
      <h2>Upgrading</h2>
      <blockquote>
        <p>
          Breaking: <code>channel.threads.create</code> now requires a{" "}
          <code>type</code>.
        </p>
      </blockquote>
      <ol>
        <li>Update the client.</li>
        <li>
          Run the backfill:
          <ul>
            <li>once per database,</li>
            <li>before the first deploy.</li>
          </ul>
        </li>
      </ol>
      <pre>
        <code>{`await channel.threads.create({
  name: "release-notes",
  type: ChannelType.PublicThread,
})`}</code>
      </pre>
      <h3>Checklist</h3>
      <ul>
        <li>
          <input type="checkbox" defaultChecked disabled /> Backfill parent ids
        </li>
        <li>
          <input type="checkbox" disabled /> Announce in the changelog
        </li>
      </ul>
      <table>
        <thead>
          <tr>
            <th>Thread</th>
            <th align="center">Visible to</th>
            <th align="right">Archives after</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Public</td>
            <td align="center">Everyone in the channel</td>
            <td align="right">24 h</td>
          </tr>
          <tr>
            <td>Private</td>
            <td align="center">Invited members</td>
            <td align="right">72 h</td>
          </tr>
        </tbody>
      </table>
      <section data-footnotes>
        <ol>
          <li id="typeset-demo-react-fn-1">
            <p>
              Only threads created before 2.3.0 were affected.{" "}
              <a
                href="#typeset-demo-react-ref-1"
                aria-label="Back to reference 1"
              >
                ↩
              </a>
            </p>
          </li>
        </ol>
      </section>
    </Typeset>
  )
}
<script setup lang="ts">
/*
 * What a CommonMark + GFM renderer (remark-gfm, markdown-it, marked) emits for
 * a typical release note, element for element: Typeset never sees the source,
 * only the markup a renderer produced from it, and none of it carries a class.
 */
import { Typeset } from "~~/registry/bases/newt/ui/typeset"
</script>

<template>
  <Typeset as="article" preset="docs" measure>
    <h1>Release 2.4.0</h1>
    <p>
      Threads can now be started from the composer, and an archived one reopens
      on the first new message. The <code>threads</code> table gained a
      <strong>parent id</strong> for private threads, which <em>fixes</em> the
      list that <del>dropped them</del> lost them after a restart<sup
        ><a href="#typeset-demo-vue-fn-1" id="typeset-demo-vue-ref-1">1</a></sup
      >. See <a href="#typeset-demo">the migration guide</a> for the backfill.
    </p>
    <h2>Upgrading</h2>
    <blockquote>
      <p>
        Breaking: <code>channel.threads.create</code> now requires a
        <code>type</code>.
      </p>
    </blockquote>
    <ol>
      <li>Update the client.</li>
      <li>
        Run the backfill:
        <ul>
          <li>once per database,</li>
          <li>before the first deploy.</li>
        </ul>
      </li>
    </ol>
    <pre><code>await channel.threads.create({
  name: "release-notes",
  type: ChannelType.PublicThread,
})</code></pre>
    <h3>Checklist</h3>
    <ul>
      <li><input type="checkbox" checked disabled /> Backfill parent ids</li>
      <li><input type="checkbox" disabled /> Announce in the changelog</li>
    </ul>
    <table>
      <thead>
        <tr>
          <th>Thread</th>
          <th align="center">Visible to</th>
          <th align="right">Archives after</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Public</td>
          <td align="center">Everyone in the channel</td>
          <td align="right">24 h</td>
        </tr>
        <tr>
          <td>Private</td>
          <td align="center">Invited members</td>
          <td align="right">72 h</td>
        </tr>
      </tbody>
    </table>
    <section data-footnotes>
      <ol>
        <li id="typeset-demo-vue-fn-1">
          <p>
            Only threads created before 2.3.0 were affected.
            <a href="#typeset-demo-vue-ref-1" aria-label="Back to reference 1"
              >↩</a
            >
          </p>
        </li>
      </ol>
    </section>
  </Typeset>
</template>

Installation

npx newtui@latest add typesetnpx shadcn@latest add @newtui/typesetnpx shadcn-vue@latest add @newtui/typesetpnpm dlx newtui@latest add typesetpnpm dlx shadcn@latest add @newtui/typesetpnpm dlx shadcn-vue@latest add @newtui/typesetyarn dlx newtui@latest add typesetyarn dlx shadcn@latest add @newtui/typesetyarn dlx shadcn-vue@latest add @newtui/typesetbunx newtui@latest add typesetbunx shadcn@latest add @newtui/typesetbunx shadcn-vue@latest add @newtui/typesetdeno run -A npm:newtui@latest add typesetdeno run -A npm:shadcn@latest add @newtui/typesetdeno run -A npm:shadcn-vue@latest add @newtui/typesetvlx newtui@latest add typesetvlx shadcn@latest add @newtui/typesetvlx shadcn-vue@latest add @newtui/typesetvp dlx newtui@latest add typesetvp dlx shadcn@latest add @newtui/typesetvp dlx shadcn-vue@latest add @newtui/typesetnubx newtui@latest add typesetnubx shadcn@latest add @newtui/typesetnubx shadcn-vue@latest add @newtui/typesetnlx newtui@latest add typesetnlx shadcn@latest add @newtui/typesetnlx shadcn-vue@latest add @newtui/typesetupx newtui@latest add typesetupx shadcn@latest add @newtui/typesetupx shadcn-vue@latest add @newtui/typeset

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Install the dependencies

npm install class-variance-authoritypnpm add class-variance-authorityyarn add class-variance-authoritybun add class-variance-authoritydeno add npm:class-variance-authorityvlt install class-variance-authorityvp add class-variance-authoritynub add class-variance-authorityni class-variance-authorityupm add class-variance-authority

Copy the source into your project

import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"

import { cn } from "@/lib/utils"

/*
 * Typeset is a wrapper and two class names — the rules live in the stylesheet
 * `add typeset` appended, keyed on `.typeset`. Nothing inside needs a class of
 * its own, which is the point: what goes in is whatever a markdown renderer
 * emitted, and it comes out with the library's rhythm.
 */
const typesetVariants = cva("typeset", {
  variants: {
    preset: {
      docs: "typeset-docs",
      chat: "typeset-chat",
      article: "typeset-article",
    },
    measure: {
      true: "typeset-measure",
      false: "",
    },
  },
  defaultVariants: {
    preset: "docs",
    measure: false,
  },
})

export interface TypesetProps
  extends
    React.HTMLAttributes<HTMLDivElement>,
    VariantProps<typeof typesetVariants> {
  /** Render as `<article>` or any other element that suits the content. */
  readonly as?: "div" | "article" | "section"
}

const Typeset = React.forwardRef<HTMLDivElement, TypesetProps>(
  ({ className, preset, measure, as: Component = "div", ...props }, ref) => (
    <Component
      ref={ref}
      className={cn(typesetVariants({ preset, measure }), className)}
      {...props}
    />
  )
)
Typeset.displayName = "Typeset"

export { Typeset, typesetVariants }
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

import { typesetVariants, type TypesetVariants } from "."

const props = withDefaults(
  defineProps<{
    class?: HTMLAttributes["class"]
    preset?: TypesetVariants["preset"]
    measure?: boolean
    /** Render as `<article>` or any other element that suits the content. */
    as?: "div" | "article" | "section"
  }>(),
  { as: "div" }
)
</script>

<template>
  <component
    :is="props.as"
    :class="
      cn(
        typesetVariants({ preset: props.preset, measure: props.measure }),
        props.class
      )
    "
  >
    <slot />
  </component>
</template>
import { cva, type VariantProps } from "class-variance-authority"

export { default as Typeset } from "./Typeset.vue"

/*
 * Typeset is a wrapper and two class names — the rules live in the stylesheet
 * `add typeset` appended, keyed on `.typeset`. Nothing inside needs a class of
 * its own, which is the point: what goes in is whatever a markdown renderer
 * emitted, and it comes out with the library's rhythm.
 */
export const typesetVariants = cva("typeset", {
  variants: {
    preset: {
      docs: "typeset-docs",
      chat: "typeset-chat",
      article: "typeset-article",
    },
    measure: {
      true: "typeset-measure",
      false: "",
    },
  },
  defaultVariants: {
    preset: "docs",
    measure: false,
  },
})

export type TypesetVariants = VariantProps<typeof typesetVariants>

Update the import paths

The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Typeset to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Typeset to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.

Usage

import { Typeset } from "@/components/ui/typeset"

export function Example() {
  return <Typeset />
}
<script setup lang="ts">
import { Typeset } from "@/components/ui/typeset"
</script>

<template>
  <Typeset />
</template>

Typeset or Markdown

Both deal with markdown, at different ends of it.

  • Typeset styles HTML that something else produced: a remark or markdown-it pipeline, MDX, a CMS field, an assistant reply run through a markdown library. You keep your renderer; Typeset gives its output the library’s rhythm.
  • Markdown takes a chat message as a string, parses chat markdown — <@id> mentions, <t:…> timestamps, ||spoilers||, -# subtext — and renders it with the library’s own components. Nothing to style afterwards, and no Typeset around it.

What it styles

Typeset never sees markdown — it sees whatever a renderer emitted from it. The left column is CommonMark and GFM, the middle is the element that reaches the wrapper, and everything in it is styled by the stylesheet without a class of its own.

Markdown Element Notes
# … ###### <h1> … <h6> One display face; sizes are em of the base.
**bold** / *italic* <strong> / <em> Bold takes the primary text colour.
~~strikethrough~~ (GFM) <del> Falls back to the muted colour.
`inline code` <code> Monospace on the surface colour.
```lang fenced block <pre><code> Scrolls sideways rather than widening the column.
[label](url), autolinks <a> Link colour, underlined.
![alt](src) <img> Never wider than the column.
> quote <blockquote> Rule on the inline start edge. Holds several paragraphs.
- item / 1. item <ul> / <ol> Nested lists keep their own counter and a tighter gap.
- [x] task (GFM) <li><input type="checkbox"> The box takes the bullet’s place.
| a | b | (GFM) <table> :-: and --: columns keep their alignment.
[^1] (GFM) <sup> + <section> The reference keeps the line; the notes sit apart.
--- <hr> One border-coloured rule.

Raw HTML a renderer passes through is covered too: <u>, <s>, <small>, <mark>, <kbd>, <sub>/<sup>, <dl>, <details> and <figure>.

API reference

Typeset

PropType
preset?"docs" | "chat" | "article"

Which of the three rhythms to start from. Each sets size, leading and flow.

Type"docs" | "chat" | "article"
Default"docs"
measure?boolean

Caps the line length at 68ch. Line length belongs to the column, not to the type.

Typeboolean
Defaultfalse
as?"div" | "article" | "section"

The element to render. Long-form content usually wants article.

Type"div" | "article" | "section"
Default"div"
children / default slot?React.ReactNode / Vue slot

The rendered markup. It needs no classes of its own.

TypeReact.ReactNode / Vue slot
className / class?string

Additional classes merged with the component defaults.

Typestring

Accessibility

The wrapper adds no semantics of its own, which is the point: the headings, lists and tables a renderer emitted keep theirs. Two things the styles do carry are accessibility decisions rather than taste — the measure exists so a line does not outrun the eye returning to the next one, and the sizes are em so a reader who has enlarged their default text enlarges all of it.

Mark an island of interface inside the prose with not-typeset and it keeps its own spacing and type.

Tokens

Typeset reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer.

  • --newt-font-sans
  • --newt-font-display
  • --newt-font-mono
  • --newt-text-secondary
  • --newt-text-primary
  • --newt-text-muted
  • --newt-radius-sm
  • --newt-brand
  • --newt-text-link
  • --newt-border
  • --newt-bg-surface
  • --newt-radius-md
  • --newt-bg-base

Changelog

  1. featscope typeset to CommonMark and GFM output#60