Basic Elements
Enhance your editor with essential formatting elements.
🌳 Blocks
Create blockquotes to emphasize important information or highlight quotes from external sources.
// Use code blocks to showcase code snippetsfunction greet() { console.info('Hello World!');}
🌱 Marks
code
formatting for easy readability.Plugins:
createBlockquotePlugin()
forblockquote
elementcreateCodeBlockPlugin()
forcode_block
elementcreateHeadingPlugin()
forh1
,h2
,... elementscreateParagraphPlugin()
forp
element
Installation
npm install @udecode/plate-basic-elements
# or
npm install @udecode/plate-block-quote @udecode/plate-code-block @udecode/plate-heading @udecode/plate-paragraph
Usage
import { createBasicElementsPlugin } from '@udecode/plate-basic-elements';
const plugins = [
// ...otherPlugins,
createBasicElementsPlugin(),
];
Keyboard Interactions
Key | Description |
---|---|
Cmd + Opt + 0 | Toggle paragraph block. |
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. |
Cmd + A | Select all text in the code block. |
API
createBasicElementsPlugin
API Block Quote
createBlockquotePlugin
API Heading
createHeadingPlugin
Options
Specifies the heading levels supported, ranging from 1 to the specified levels.
API Paragraph
createParagraphPlugin
API Code Block
createCodeBlockPlugin
Options
Determines if syntax highlighting is enabled.
Determines if popular syntax should be displayed first.
Defines deserializers for the code block plugin.
Hotkeys to trigger a code block action.
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.