Code applies the code leaf mark to inline text. Use Code Block for fenced or multiline code; this page is only for inline code spans.
BasicMarksKit includes CodePlugin, CodeLeaf, the backtick input rule, and a mod+e shortcut.
'use client';
import {
BoldRules,
CodeRules,
HighlightRules,
ItalicRules,
MarkComboRules,
ScriptRules,
StrikethroughRules,
UnderlineRules,
} from '@platejs/basic-nodes';
import {
BoldPlugin,
CodePlugin,
HighlightPlugin,
ItalicPlugin,
KbdPlugin,
ScriptPlugin,
StrikethroughPlugin,
UnderlinePlugin,
} from '@platejs/basic-nodes/react';
import { CodeLeaf } from '@/components/editor/code';
import { HighlightLeaf } from '@/components/editor/highlight';
import { KbdLeaf } from '@/components/editor/kbd';
export const BasicMarksKit = [
BoldPlugin.configure({
inputRules: [
BoldRules.markdown({ variant: '*' }),
BoldRules.markdown({ variant: '_' }),
MarkComboRules.markdown({ variant: 'boldItalic' }),
MarkComboRules.markdown({ variant: 'boldUnderline' }),
MarkComboRules.markdown({ variant: 'boldItalicUnderline' }),
MarkComboRules.markdown({ variant: 'italicUnderline' }),
],
}),
ItalicPlugin.configure({
inputRules: [
ItalicRules.markdown({ variant: '*' }),
ItalicRules.markdown({ variant: '_' }),
],
}),
UnderlinePlugin.configure({
inputRules: [UnderlineRules.markdown()],
}),
CodePlugin.configure({
component: CodeLeaf,
inputRules: [CodeRules.markdown()],
shortcuts: { toggle: { keys: 'mod+e' } },
}),
StrikethroughPlugin.configure({
inputRules: [StrikethroughRules.markdown()],
shortcuts: { toggle: { keys: 'mod+shift+x' } },
}),
ScriptPlugin.configure({
inputRules: [
ScriptRules.markdown({ value: 'sub' }),
ScriptRules.markdown({ value: 'sup' }),
],
shortcuts: {
subscript: {
keys: 'mod+comma',
handler: ({ editor }) => {
editor.plugin(ScriptPlugin).update.toggle('sub');
},
},
superscript: {
keys: 'mod+period',
handler: ({ editor }) => {
editor.plugin(ScriptPlugin).update.toggle('sup');
},
},
},
}),
HighlightPlugin.configure({
component: HighlightLeaf,
inputRules: [
HighlightRules.markdown({ variant: '==' }),
HighlightRules.markdown({ variant: '≡' }),
],
shortcuts: { toggle: { keys: 'mod+shift+h' } },
}),
KbdPlugin.configure({ component: KbdLeaf }),
] as const;'use client';
import {
BoldRules,
CodeRules,
HighlightRules,
ItalicRules,
MarkComboRules,
ScriptRules,
StrikethroughRules,
UnderlineRules,
} from '@platejs/basic-nodes';
import {
BoldPlugin,
CodePlugin,
HighlightPlugin,
ItalicPlugin,
KbdPlugin,
ScriptPlugin,
StrikethroughPlugin,
UnderlinePlugin,
} from '@platejs/basic-nodes/react';
import { CodeLeaf } from '@/components/editor/code';
import { HighlightLeaf } from '@/components/editor/highlight';
import { createPlateEditor } from 'platejs/react';
import { BasicMarksKit } from '@/components/editor/basic-marks';
export const editor = createPlateEditor({
plugins: [...BasicMarksKit],
});import { createPlateEditor } from 'platejs/react';
import { BasicMarksKit } from '@/components/editor/basic-marks';
export const editor = createPlateEditor({
Pass CodePlugin to MarkToolbarButton so the button uses the configured mark key.
import { Code2Icon } from 'lucide-react';
import { CodePlugin } from '@platejs/basic-nodes/react';
import { MarkToolbarButton } from '@/components/editor/mark-toolbar-button';
export function CodeToolbarButton() {
return (
<MarkToolbarButton plugin={CodePlugin} tooltip="Code (⌘+E)">
<Code2Icon />
</MarkToolbarButton>
);
}Install the mark package.
Add CodePlugin directly when you want the default <code> render.
import { CodePlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
export const editor = createPlateEditor({
plugins: [CodePlugin],
});import { CodePlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
export const editor = createPlateEditor({
plugins: [CodePlugin],
});Configure the registry leaf, input rule, and shortcut when you want the same behavior as the kit.
import { CodeRules } from '@platejs/basic-nodes';
import { CodePlugin } from '@platejs/basic-nodes/react';
import { CodeLeaf } from '@/components/editor/code';
export const codePlugin = CodePlugin.configure({
component: CodeLeaf,
inputRules: [CodeRules.markdown()],
shortcuts: { toggle: { keys: 'mod+e' } },
});import { CodeRules } from '@platejs/basic-nodes';
import { CodePlugin } from '@platejs/basic-nodes/react';
import { CodeLeaf } from '@/components/editor/code';
export const codePlugin = CodePlugin.configure({
component: CodeLeaf,
inputRules: [CodeRules.markdown()],
shortcuts: { toggle: { keys: 'mod+e' } },
});| Surface | Owner | What It Does |
|---|---|---|
BaseCodePlugin | @platejs/basic-nodes | Headless inline code mark, HTML parser, render tag, selection rule, and toggle transform. |
CodePlugin | @platejs/basic-nodes/react | React wrapper for the headless code mark. |
CodeRules.markdown | @platejs/basic-nodes | Optional backtick input rule. |
CodeLeaf | Registry UI | Styled inline code leaf using PlateLeaf. |
CodeLeafStatic | Registry UI | Static rendering version using PliteLeaf. |
BasicMarksKit | Registry | Adds CodePlugin, CodeLeaf, CodeRules.markdown(), and mod+e. |
MarkToolbarButton | Registry UI | Reads active mark state and calls the mark toggle hook. |
The package owns inline code semantics. The registry owns visual styling and toolbar placement.
| Behavior | Source |
|---|---|
| Mark key | editor.plugin(CodePlugin).schema.key (default: code) |
| Mark declaration | schema.mark: property.boolean({ default: false, omitDefault: true }) |
| Toggle command | tx.code.toggle() toggles the resolved schema key. |
| Selection affinity | hard |
| HTML tags | code |
| HTML styles | font-family: Consolas |
| HTML guard | Skips code inside pre and paragraph-level Consolas blocks. |
| Render output | code |
| Kit shortcut | mod+e |
| API | Package | Use |
|---|---|---|
BaseCodePlugin | @platejs/basic-nodes | Headless inline code plugin. |
CodePlugin | @platejs/basic-nodes/react | React inline code plugin. |
CodeRules.markdown() | @platejs/basic-nodes | Creates the backtick mark input rule. |
tx.code.toggle() | @platejs/basic-nodes | Toggles the inline code mark at the selection. |
CodeLeaf | Registry UI | Styled client inline code leaf. |
CodeLeafStatic | Registry UI | Styled static inline code leaf. |
import { Code2Icon } from 'lucide-react';
import { CodePlugin } from '@platejs/basic-nodes/react';
import { MarkToolbarButton } from '@/components/editor/mark-toolbar-button';
export function CodeToolbarButton() {
return (
<MarkToolbarButton plugin={CodePlugin} tooltip="Code (⌘+E)">
<Code2Icon />
</MarkToolbarButton>
);
}