The Code Chip

By Steph15
Scroll to open

16languages in the dropdown

The Code Chip

A block of source, highlighted, with line numbers and a copy button. It is the least surprising chip on the platform and the one with the most interesting edges, because code is the one kind of text that cares deeply about characters the rest of the format treats as punctuation.

Here Is the Chip, Rendering Itself

The block below is a Code chip. What it contains is the Java class that turns a chext block into a Code chip. There is no trick to it: the entire builder is two assignments and a return.

java
@Component
public class CodeChipBuilder extends ChipBuilderSupport<PayloadCodeChip> {

  @Override
  public boolean supports(@NonNull String type) {
    return "CODE".equals(type);
  }

  @Override
  @NonNull
  public BuildResult<PayloadCodeChip> build(
      @NonNull ParsedBlock block, @NonNull ParseContext context, int rowIndex) {
    var payload = new PayloadCodeChip();
    payload.setCode(String.join("\n", block.lines()));
    var language = block.chipEdits().get("language");
    if (language != null) {
      payload.setLanguage(language);
    }
    return validated(chip("CODE", "FULL", rowIndex, payload), block.startLine());
  }
}

Most builders run their lines through a helper that merges trailing backslashes into line continuations. This one deliberately does not, because a backslash at the end of a line means something in almost every language a person would paste here.

The Parser Will Eat Your Comments

This is the sharp edge and it deserves the top of the list rather than a footnote. The chext block parser drops any line beginning with two forward slashes, and it does so before any chip builder sees the content. There is no exception for Code blocks and no escape sequence. Paste a Go file with a package comment at the top and the comment is simply gone from the published page, with no warning and no diagnostic.

The Undocumented Workaround

The parser strips trailing whitespace from each line but never leading whitespace, so the comment test only matches at column zero. Indent the comment by a single space and it survives intact. That is a real fix and an embarrassing one, and the fact that it works is currently written down nowhere except here.

go
package main

import "fmt"

 // this comment is indented one space, which is the only reason you can read it
func main() {
	fmt.Println("hello")
}

The Colon Problem Is Worse

A line starting with a colon at column zero opens a new chip. Inside a Code block that does not just lose a line, it truncates the block and the remainder is discarded: its marker matches no chip type, so the parser records an error and drops it. The content does not resurface anywhere. CSS is the obvious casualty, because a rule that opens on a pseudo-selector at the start of a line ends the snippet there. So do assembly labels and a fair amount of YAML. Unlike the comment case there is no workaround, because indenting CSS to publish it is not a thing anyone should be asked to do. This is a genuine unfixed limitation of the format rather than a quirk of the chip.

One More, Smaller

If the last line of your snippet is a bare pipe character, it is removed. A single pipe on its own line is the format's way of saying this chip connects visually to the next one, and the Code builder inherits that rule along with everything else.

Languages offered in the picker

16

Grammars actually shipped in the bundle

192

Maximum code length

65535 characters

Language auto-detection

never built

Revisions since launch

0

Sixteen Offered, One Hundred and Ninety-Two Shipped

The highlighter is imported as the full library rather than a core build with selected grammars registered on top. That means every visitor downloads support for a hundred and ninety-two languages so that sixteen can appear in a dropdown, and the server-side renderer loads the same bundle. It is a real cost and it also means that adding C, Ruby, YAML, Markdown, Dockerfile or diff is a one file change with no bundle impact at all, since the grammars are already there. That has not been done, which is harder to defend than the bundle size.

Highlighted Twice, Identically

Highlighting runs synchronously in the component body with no effect hook around it, so it executes during server rendering and again during hydration. That sounds wasteful and it is what makes the chip safe: the same pure function over the same input produces byte-identical markup on both sides, so there is no hydration mismatch and no flash of unhighlighted code. A crawler that never runs JavaScript still receives coloured, structured source.

It Is Always Dark

No highlight.js stylesheet is imported. The token colours are about fourteen hand-written rules in a palette close to Material Palenight, with the container hardcoded to a near-black background. There is no light mode handling and no theme variable other than the accent colour on the language label and the copy button. On a light themed slate the Code chip stays a dark slab in the middle of the page. Some people read that as deliberate. It was not.

The Wishlist Entry, Scored

75%

Syntax highlighting

Line numbers

Copy to clipboard

Language detection: never built, an unknown language silently renders as plain text

Two Things Still Wrong in the Rendering

The line number gutter sits inside the horizontally scrolling container rather than pinned beside it, so scrolling right on a long line slides the numbers off the screen. And there is no maximum height anywhere, which means a chip approaching the sixty-five thousand character limit renders at full height and takes the page layout with it. Neither is hard to fix. Both are still there.

The HTML That Is Called XML

The language picker offers HTML and stores the value as xml, because that is what the highlighter calls it. Writing the language as html in a text file stores html, which the highlighter also accepts as an alias. Both highlight correctly and the header label above the block reads differently depending on which way the chip was created. The aliasing lives inside the highlighter, not in this codebase, and it does not round trip.

Dates31.03.2026 – 15.07.2026
31.03.2026Shipped, alongside the Goal chip, in a single release
31.03.2026
15.07.2026Touched twice since, both cosmetic
15.07.2026

Shipped and Left Alone

The Code chip went out on 31 March 2026 and has had no revision since. Everything described above as a rough edge is a rough edge that is live right now. A feature page that only listed the parts that went well would be shorter and considerably less useful.

"

Code is the one kind of text that cares which column you started in.

"