Skip to content
GitHub

Heading

The heading node is used to represent blocks of heading in the document.

import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'

import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/react'
import { useMemo } from 'react'

import { defineExtension } from './extension'
import Toolbar from './toolbar'

export default function Editor() {
  const editor = useMemo(() => {
    return createEditor({ extension: defineExtension(), defaultContent: '<h1>H1</h1>' })
  }, [])

  return (
    <ProseKit editor={editor}>
      <div className='box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow flex flex-col bg-white dark:bg-gray-950 color-black dark:color-white'>
        <Toolbar />
        <div className='relative w-full flex-1 box-border overflow-y-scroll'>
          <div ref={editor.mount} className='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none outline-0 [&_span[data-mention="user"]]:text-blue-500 [&_span[data-mention="tag"]]:text-violet-500'></div>
        </div>
      </div>
    </ProseKit>
  )
}
import { defineHeadingfunction defineHeading(): HeadingExtension
@public
} from 'prosekit/extensions/heading'
const extensionconst extension: HeadingExtension = defineHeadingfunction defineHeading(): HeadingExtension
@public
()
editorconst editor: Editor<HeadingExtension>.commands
Editor<HeadingExtension>.commands: ToCommandAction<{
    setHeading: [attrs?: HeadingAttrs | undefined];
    insertHeading: [attrs?: HeadingAttrs | undefined];
    toggleHeading: [attrs?: HeadingAttrs | undefined];
}>
All {@link CommandAction } s defined by the editor.
.setHeading
setHeading: CommandAction
(attrs?: HeadingAttrs | undefined) => boolean
Execute the current command. Return `true` if the command was successfully executed, otherwise `false`.
({ levelHeadingAttrs.level: number: 1 })
editorconst editor: Editor<HeadingExtension>.commands
Editor<HeadingExtension>.commands: ToCommandAction<{
    setHeading: [attrs?: HeadingAttrs | undefined];
    insertHeading: [attrs?: HeadingAttrs | undefined];
    toggleHeading: [attrs?: HeadingAttrs | undefined];
}>
All {@link CommandAction } s defined by the editor.
.toggleHeading
toggleHeading: CommandAction
(attrs?: HeadingAttrs | undefined) => boolean
Execute the current command. Return `true` if the command was successfully executed, otherwise `false`.
({ levelHeadingAttrs.level: number: 1 })
editorconst editor: Editor<HeadingExtension>.commands
Editor<HeadingExtension>.commands: ToCommandAction<{
    setHeading: [attrs?: HeadingAttrs | undefined];
    insertHeading: [attrs?: HeadingAttrs | undefined];
    toggleHeading: [attrs?: HeadingAttrs | undefined];
}>
All {@link CommandAction } s defined by the editor.
.insertHeading
insertHeading: CommandAction
(attrs?: HeadingAttrs | undefined) => boolean
Execute the current command. Return `true` if the command was successfully executed, otherwise `false`.
({ levelHeadingAttrs.level: number: 1 })
Non-AppleAppleDescription
Ctrl-Alt-1Command-Option-1Set the current block to an H1 node
Ctrl-Alt-2Command-Option-2Set the current block to an H2 node
Ctrl-Alt-3Command-Option-3Set the current block to an H3 node
Ctrl-Alt-4Command-Option-4Set the current block to an H4 node
Ctrl-Alt-5Command-Option-5Set the current block to an H5 node
Ctrl-Alt-6Command-Option-6Set the current block to an H6 node
BackspaceBackspaceWhen the text cursor is at the start of a heading node, set it to paragraph

Type # and a space to create a heading. One # makes an H1 heading, two ## make an H2 heading, and so on.