|Kit

Prose

Polymorphic

Styles rendered HTML you don't control, such as markdown turned into HTML, so a project subject or a changelog looks like the rest of the kit.

Prose is a wrapper for HTML that your app renders but doesn't write element by element: a project subject, an announcement or a changelog that comes out of a markdown renderer or a CMS. It isn't a markdown parser. Your app turns the markdown into HTML, and Prose styles the plain elements inside it to match the kit.

import { Prose } from "@42-central/ui-react/prose";
import "@42-central/ui-react/prose/styles.css";

<Prose dangerouslySetInnerHTML={{ __html: sanitize(html) }} />
<Prose>{renderMarkdown(source)}</Prose>

The element styles ship as a separate stylesheet. Import @42-central/ui-react/prose/styles.css once, next to theme.css. Without it, Prose renders unstyled HTML.

Playground

Component

Loading preview

Props

Code

<Component size="md" measure={false} />

A project subject

A subject rendered from markdown, passed as an HTML string. The headings use Title's scale, inline code looks like Code, the code block has CodeBlock's frame, the table looks like Table, and the highlight, the keys and the links look like Mark, Kbd and Anchor.

minishell

As beautiful as a shell. Write a small command interpreter that reads a line, parses it and runs it, the way bash does. You will learn a lot about processes and file descriptors.

Program nameTurn in filesVersion
minishellMakefile, *.h, *.c7.1
Libft authorizedYes—

Mandatory part

Your shell should:

  1. Display a prompt when waiting for a new command.
  2. Search and launch the right executable, based on the PATH variable or a relative or absolute path.
  3. Handle redirections:
    • < redirects input, > redirects output.
    • << reads input until a line containing the delimiter.
  4. Handle Ctrl-C, Ctrl-D and Ctrl-\ like bash.

Read the bash manual before you start. When in doubt, take bash as a reference.

Example

$ echo "hello" | tr a-z A-Z > out.txt
$ cat out.txt
HELLO

Before you push

  • No memory leaks, checked with valgrind
  • The Norm passes on every file
  • The bonus part, only once the mandatory part is perfect
Hint: where do signals go?

A signal reaches every process in the foreground group. Think about what your shell should do while a child runs.


Questions go to the project channel. Good luck!

Code

<Prose measure dangerouslySetInnerHTML={{ __html: subjectHtml }} />

What it styles

ElementLooks like
h1 to h6Title at the same level: h1 is 4xl, h6 is md
p, strong, emBody text in the primary text colour
aAnchor: the same --btn-link-* colours, underline and focus ring
ul, ol, nested listsDisc, circle and square bullets; numbers, letters and roman numerals. An ol or ul with a type (1, a, i, disc, circle, square) keeps it
Task listsGitHub's <li><input type="checkbox"> items, drawn like Checkbox
blockquoteA hairline on the start side, in the secondary text colour
codeCode's neutral pill, at the size of the text around it
preCodeBlock's frame, without highlighting. It reads left to right in RTL text, like CodeBlock
tableTable's surface, header and row lines. Markdown's column align is kept
img, video, figure, figcaptionImage's radius and Figure's caption
hrDivider's hairline
markMark's yellow highlight
kbdKbd's key cap. In <kbd><kbd>Ctrl</kbd>+<kbd>K</kbd></kbd>, only the inner keys are caps
details, summaryA quiet surface with a chevron that mirrors in RTL
dl, footnotesBold terms; GitHub's footnotes section in small secondary text

Heading 4

Heading 5
Heading 6

Text with strong, emphasis, deleted and a combination: Ctrl+Shift+P.

  1. An ordered list with an explicit type="a".
  2. It keeps its letters.
Evaluation
Three peers grade your project.
Mountains above a sea of clouds
A figure and its caption.

Code

<Prose measure dangerouslySetInnerHTML={{ __html: elementsHtml }} />

Size

size sets the body text to sm (14px), md (16px, the default) or lg (18px). Headings, spacing, code and tables scale with it. At md, each heading is exactly the size of a Title of the same level.

size="sm"

Run make, then press Enter. Headings, spacing and code all follow the size.

size="md"

Run make, then press Enter. Headings, spacing and code all follow the size.

size="lg"

Run make, then press Enter. Headings, spacing and code all follow the size.

Code

<Prose size="sm">…</Prose>
<Prose size="md">…</Prose>
<Prose size="lg">…</Prose>

Measure

measure caps the line length at 65 characters, a comfortable reading width. It's off by default, because the layout around Prose usually decides how wide it is. For another width, pass a max-w-* class instead.

Kit components inside Prose

Prose only styles plain elements. A kit component inside it keeps its own look:

  • The styles are in CSS's components layer, under Tailwind's utilities. Any property a component's classes set wins over Prose's.
  • Every selector is a bare element name, so any class beats it.

A kit component can still pick up properties it doesn't set itself, such as the margins Prose gives a <p>. To opt a block out completely, give it the not-prose class. Prose doesn't style that element or anything inside it.

Prose styles the plain elements around this card:

Deadline

Friday, 23:42. 3 days left

The card has className="not-prose", so its paragraphs keep the card's own spacing and colours.

Code

<Prose measure>
  <p>Prose styles the plain elements around this card:</p>
  <Card className="not-prose">
    <p className="font-medium">Deadline</p>
    <p className="text-sm text-black/60 dark:text-white/60">
      Friday, 23:42. <Badge color="orange">3 days left</Badge>
    </p>
  </Card>
  <p>The card has <code>className="not-prose"</code>, …</p>
</Prose>

not-prose only counts between the Prose and the element. A Prose inside someone else's not-prose, such as this site's demo frames, is still styled.

If you render markdown with React (MDX, react-markdown), you can also map elements to kit components, for example a to Anchor so links go through your router. They keep their own styles inside Prose.

Customising

To restyle one element, put a descendant class on Prose. It wins over the default:

<Prose className="[&_h2]:text-brand-500 [&_table]:text-xs">…</Prose>

The colours are custom properties on the root, so you can change one role for every element that uses it: --prose-body, --prose-heading, --prose-quote, --prose-muted, --prose-hairline, --prose-code-bg and the rest listed at the top of styles.css. Links read --btn-link-text and --btn-link-hover, so retheming those changes Anchor, <Button variant="link"> and Prose's links together.

Security

Prose doesn't sanitize anything. HTML passed through dangerouslySetInnerHTML runs as is, scripts and event handlers included. Sanitize anything that a user can write (a subject, a comment, an announcement) on the server, with a library such as DOMPurify or rehype-sanitize, before you pass it in.

Server components

Prose is a server component: it has no "use client" and no state. It renders a <div>, or with asChild, your own element (an <article>, say).

Browser support

The styles use CSS @scope, supported in Chrome 118, Safari 17.4 and Firefox 146 or later. Headings trim their leading with text-box-trim like Title; browsers without it keep normal leading.

Anatomy

Prose is a single part: one element that carries the hooks the stylesheet scopes to.

<div data-prose data-size="md" data-measure data-testid="subject">
  {/* your HTML */}
  <div className="not-prose">{/* left alone */}</div>
</div>

testId renders as data-testid on that element. See Testing. data-measure is present only when measure is on.

API

Prop

Type

Every other prop is forwarded to the root <div>.

Accessibility

  • Prose adds no roles. The HTML keeps its own semantics: headings, lists, tables and details work with assistive technology as they would anywhere else. Pass asChild with an <article> to make the document a landmark-like region of its own.
  • The document outline is yours. Prose styles an h2 like a level-2 Title, so render headings at the right level rather than picking them by size.
  • Links are underlined, so they don't rely on colour alone (WCAG 1.4.1), and they and summary show the kit's focus ring.
  • Task list checkboxes stay real, disabled <input>s, so screen readers announce them as checked or not checked.
  • Images need their alt text in the HTML. Prose can't add it.

Changelog

v0.30.0
  • New Prose styles rendered HTML like the kit (opt-in prose/styles.css), with size and measure

    #484
  • Inline code and single keys read left to right on RTL pages

    #490

On this page