FrameworkJavaScript
Code block: syntax-highlighted code
A syntax-highlighted code block with a language picker, an optional line-number gutter, and a copy-to-clipboard button. It supports 30+ languages via Prism. The LaTeX and Mermaid languages include a live preview tab.
Pasting markdown fenced code blocks (``) or <pre> elements automatically creates a code block. The language comes across whenever the pasted source names it: a fence that opens with ``sql, or a labelled code block copied out of an app such as Gemini.
Import
TypeScript
import { Code } from '@bloklabs/core/tools';Save Data
TypeScript
interface CodeData {
code: string; // Raw code text (not HTML)
language: string; // Language identifier, e.g. "javascript", "plain text"
lineNumbers?: boolean; // Whether to show line numbers in the gutter
filename?: string; // File name shown above the code, e.g. "block.ts"
}JSON
{
"id": "cod001",
"type": "code",
"data": {
"code": "const greeting = 'hello';\nconsole.log(greeting);",
"language": "javascript",
"lineNumbers": true
}
}Usage Example
TypeScript
import { Blok } from '@bloklabs/core';
import { Code } from '@bloklabs/core/tools';
const editor = new Blok({
holder: 'editor',
tools: {
code: {
class: Code,
inlineToolbar: false,
},
},
});