agentskit.js

CodeBlock

Headless code block with optional copy button. Style via data-ak-code-block.

Renders a pre > code block. An optional copy button (copyable) writes the code string to the clipboard using the Clipboard API. Language is forwarded as data-ak-language for syntax-highlighting hooks.

No syntax highlighting is bundled β€” attach a highlighter (e.g. highlight.js, shiki, Prism) inside the CSS layer using the language attribute.

#Props

PropTypeDefaultDescription
codestringβ€”Source code to display
languagestringβ€”Language hint (e.g. "tsx", "python")
copyablebooleanfalseRender a copy-to-clipboard button

#Example

import { CodeBlock } from '@agentskit/react'

export function InlineFence({ code, lang }) {
  return <CodeBlock code={code} language={lang} copyable />
}

#data-ak-code-block

AttributePresent when
data-ak-code-blockalways
data-ak-languagelanguage prop is set
data-ak-copyon the copy <button> when copyable
[data-ak-code-block] pre {
  overflow-x: auto;
  padding: 1rem;
  border-radius: 0.5rem;
  background: var(--ak-surface-code);
}

[data-ak-copy] {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}

#Per-framework

FrameworkImport
Reactimport { CodeBlock } from '@agentskit/react'
Inkimport { CodeBlock } from '@agentskit/ink'

Explore nearby

✎ Edit this page on GitHubΒ·Found a problem? Open an issue β†’Β·How to contribute β†’

On this page