Header block: headings H1 to H6
Heading blocks from H1 to H6. It supports several toolbox entries, one per heading level, and keyboard shortcuts (# ## ### etc.).
Every level also has an optional toggle that collapses and expands its children. The toolbox lists "Toggle heading 1" through "Toggle heading 6", reachable with the markdown shortcuts ># through >######.
Converting an existing block into a toggle heading adopts its section: use "Turn into" or blocks.convert with isToggleable: true. Every following sibling becomes a child of the new toggle, up to the next heading of the same or higher rank. This matches Notion.
Import
import { Header } from '@bloklabs/core/tools';Configuration
| Option | Type | Default | Description |
|---|---|---|---|
placeholder | string | level name (e.g. "Heading 2", localised) | Placeholder text shown in an empty heading block. |
levels | number[] | [1,2,3,4,5,6] | Restrict which heading levels are available. |
defaultLevel | number | 2 | The heading level used when inserting a new header block. |
levelOverrides | Record<number, { tag?, name?, size?, marginTop?, marginBottom? }> | {} | Per-level overrides for HTML tag, display name, or CSS values. |
shortcuts | Record<number, string> | undefined | Custom markdown prefixes per heading level. If omitted, the default markdown prefixes (#, ## …) are used. Pass an empty object {} to disable the plain heading prefixes. The toggle-heading prefixes ( |
anchorIds | boolean | (text: string, blockId: string) => string | undefined | Opt-in text-derived anchor ids on rendered headings.
Ids stay in sync on text edits and survive level changes. A heading that carries its own data.anchor keeps that instead. Cross-block duplicate dedup is out of scope, so consumers dedup themselves. |
Save Data
interface HeaderData {
text: RichText; // Heading text as segments (HeaderToolData holds HTML)
level: number; // 1–6
isToggleable?: boolean; // true when the heading has toggle (collapse/expand)
textColor?: string; // Block colour preset, present when set
backgroundColor?: string; // Block background colour preset, present when set
anchor?: string; // Anchor id for in-document links, present when set
}{
"id": "def456",
"type": "header",
"data": {
"text": [{ "text": "Getting Started" }],
"level": 2
}
}Usage Example
import { Blok } from '@bloklabs/core';
import { Header } from '@bloklabs/core/tools';
const editor = new Blok({
holder: 'editor',
tools: {
header: {
class: Header,
levels: [1, 2, 3],
defaultLevel: 2,
placeholder: 'Enter a heading',
},
},
});