Basic Elements
Enhance your editor with essential formatting elements.
'use client';
import React from 'react';
import { Plate } from '@udecode/plate-common/react';
import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = useCreateEditor({
plugins: [...editorPlugins],
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
Plugins:
BlockquotePlugin
forblockquote
elementCodeBlockPlugin
forcode_block
elementHeadingPlugin
forh1
,h2
,... elements
Installation
npm install @udecode/plate-basic-elements
# or
npm install @udecode/plate-block-quote @udecode/plate-code-block @udecode/plate-heading
Usage
import { BasicElementsPlugin, CodeBlockPlugin } from '@udecode/plate-basic-elements/react';
import Prism from 'prismjs';
const plugins = [
// ...otherPlugins,
BasicElementsPlugin.configurePlugin(CodeBlockPlugin, {
options: {
prism: Prism,
},
}),
];
Keyboard Shortcuts
Key | Description |
---|---|
Cmd + Opt + 1 | Toggle heading 1 block. |
Cmd + Opt + 2 | Toggle heading 2 block. |
Cmd + Opt + 3 | Toggle heading 3 block. |
Cmd + Shift + . | Toggle the blockquote formatting for selected text. |
Plugins
BasicElementsPlugin
BlockquotePlugin
HeadingPlugin
Options
Specifies the heading levels supported, ranging from 1 to the specified levels.
CodeBlockPlugin
Options
Determines if syntax highlighting is enabled.
Determines if popular syntax should be displayed first.
Defines deserializers for the code block plugin.
API Code Block
isCodeBlockEmpty
Checks if the selection is inside an empty code block.
Parameters
The editor instance.
Returns
Returns true if the selection is in an empty code block.
isSelectionAtCodeBlockStart
Checks if the selection is at the start of the first code line in a code block.
Parameters
The editor instance.
Returns
Returns true if the selection is at the start of the first code line in a code block.
indentCodeLine
Indents the code line if the selection is expanded or there are no non-whitespace characters at left of the cursor. The indentation is 2 spaces by default.
Parameters
The editor instance.
insertCodeBlock
Inserts a code block by setting the node to code line and wrapping it with a code block. If the cursor is not at the block start, it inserts a break before the code block.
Parameters
The editor instance.
insertCodeLine
Inserts a code line starting with the specified indentation depth.
Parameters
- Default:
0
The editor instance.
The depth of indentation for the code line.
outdentCodeLine
Outdents a code line, removing two whitespace characters if present.
Parameters
The editor instance.
toggleCodeBlock
Toggles the code block in the editor.
Parameters
The editor instance.
unwrapCodeBlock
Unwraps the code block in the editor.
Parameters
The editor instance.
useCodeBlockCombobox
State
The code block element.
Set element value callback.
Returns
The props for the command item.
useCodeBlockElementState
Parameters
The code block element.
Returns
The CSS class name for the code block element, representing the selected language.
The syntax plugin option.
useCodeSyntaxLeaf
Parameters
Returns
The props for the token.