Prose
PolymorphicStyles 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
Dir
Presets
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 name | Turn in files | Version |
|---|---|---|
minishell | Makefile, *.h, *.c | 7.1 |
| Libft authorized | Yes | — |
Mandatory part
Your shell should:
- Display a prompt when waiting for a new command.
- Search and launch the right executable, based on the
PATHvariable or a relative or absolute path. - Handle redirections:
<redirects input,>redirects output.<<reads input until a line containing the delimiter.
- Handle Ctrl-C, Ctrl-D and Ctrl-\ like
bash.
Read the bash manual before you start. When in doubt, take
bashas 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
| Element | Looks like |
|---|---|
h1 to h6 | Title at the same level: h1 is 4xl, h6 is md |
p, strong, em | Body text in the primary text colour |
a | Anchor: the same --btn-link-* colours, underline and focus ring |
ul, ol, nested lists | Disc, 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 lists | GitHub's <li><input type="checkbox"> items, drawn like Checkbox |
blockquote | A hairline on the start side, in the secondary text colour |
code | Code's neutral pill, at the size of the text around it |
pre | CodeBlock's frame, without highlighting. It reads left to right in RTL text, like CodeBlock |
table | Table's surface, header and row lines. Markdown's column align is kept |
img, video, figure, figcaption | Image's radius and Figure's caption |
hr | Divider's hairline |
mark | Mark's yellow highlight |
kbd | Kbd's key cap. In <kbd><kbd>Ctrl</kbd>+<kbd>K</kbd></kbd>, only the inner keys are caps |
details, summary | A quiet surface with a chevron that mirrors in RTL |
dl, footnotes | Bold 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.
- An ordered list with an explicit
type="a". - It keeps its letters.
- Evaluation
- Three peers grade your project.
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
componentslayer, under Tailwind'sutilities. 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
Proseadds no roles. The HTML keeps its own semantics: headings, lists, tables anddetailswork with assistive technology as they would anywhere else. PassasChildwith an<article>to make the document a landmark-like region of its own.- The document outline is yours. Prose styles an
h2like a level-2Title, 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
summaryshow 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
alttext in the HTML. Prose can't add it.