Code Block

Display copyable, syntax-highlighted source without a live preview.

Terminal
bun add @heyo-sh/heyo-docs
<CodeBlock language="bash" title="Terminal">
{"bun add @heyo-sh/heyo-docs"}
</CodeBlock>

CodeBlock displays source code, commands, configuration, or response samples when there is no rendered result to preview. It includes syntax highlighting and a copy control, so readers can take an example directly into their project.

Label code clearly

Set language for accurate highlighting and use title when the reader needs more context than a language label provides. Enable line numbers when the surrounding explanation refers to a specific line.

heyo-docs.config.json
{
"contentDir": "content",
"theme": "system"
}

Use CodeSnippet instead when the same source can produce a useful live preview. Keep code blocks focused on a single operation so copying is safe and easy to understand.

Let readers edit an example

Set editable to make the code area editable. It defaults to false; when it is enabled, the copy control copies the reader's current changes rather than the initial source.

reader-settings.json
<CodeBlock editable language="json" title="reader-settings.json">
{"{ \"theme\": \"dark\" }"}
</CodeBlock>

Show a focused configuration change

A titled block with line numbers works well when the surrounding guide refers to a few lines in a longer configuration object.

heyo-docs.config.ts
export default {
  title: 'Orbit',
  theme: 'system',
  navigation: [{ title: 'Guides', path: '/quickstart' }],
};
<CodeBlock language="ts" showLineNumbers title="heyo-docs.config.ts">
{"export default {
  title: 'Orbit',
  theme: 'system',
  navigation: [{ title: 'Guides', path: '/quickstart' }],
};"}
</CodeBlock>

Properties

languagestringoptional

The syntax-highlighting language. It defaults to plain text and recognises common aliases such as ts, js, bash, json, md, and yaml.

titleReactNodeoptional

The label shown above the code. It defaults to the resolved language.

showLineNumbersbooleanoptional

Adds line-number data to the code block. It defaults to false.

editablebooleanoptional

Makes the source editable in place. It defaults to false; the copy control uses the edited source while it is enabled.

childrenReactNodeoptional

The source code to highlight and copy.

classNamestringoptional

Extra classes applied to the outer code block.