Text Formatting
Add style and emphasis to your text using various formatting options.
Make text bold, italic, underlined, or apply a combination of these styles for emphasis.
Add strikethrough to indicate deleted content, use
inline code for technical terms, or highlight important information.Format mathematical expressions with subscript and superscript text.
Show keyboard shortcuts like ⌘ + B for bold or ⌘ + I for italic formatting.
1
100%
Files
'use client';
import * as React from 'react';
import { Plate, usePlateEditor } from 'platejs/react';
import { EditorKit } from '@/components/editor/editor-kit';
import { Editor, EditorContainer } from '@/components/ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = usePlateEditor({
plugins: EditorKit,
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
Basic text formatting marks like bold, italic, and underline.
basic-marks-demo


功能特性
- 应用删除线格式标记已删除或过时内容
- 支持快捷键快速格式化
- 默认渲染为
<s>HTML 元素
套件使用
安装
最快捷的添加删除线插件方式是使用 BasicMarksKit,它包含预配置的 StrikethroughPlugin 以及其他基础标记和它们的 Plate UI 组件。
'use client';
import {
BoldPlugin,
CodePlugin,
HighlightPlugin,
ItalicPlugin,
KbdPlugin,
StrikethroughPlugin,
SubscriptPlugin,
SuperscriptPlugin,
UnderlinePlugin,
} from '@platejs/basic-nodes/react';
import { CodeLeaf } from '@/components/ui/code-node';
import { HighlightLeaf } from '@/components/ui/highlight-node';
import { KbdLeaf } from '@/components/ui/kbd-node';
export const BasicMarksKit = [
BoldPlugin,
ItalicPlugin,
UnderlinePlugin,
CodePlugin.configure({
node: { component: CodeLeaf },
shortcuts: { toggle: { keys: 'mod+e' } },
}),
StrikethroughPlugin.configure({
shortcuts: { toggle: { keys: 'mod+shift+x' } },
}),
SubscriptPlugin.configure({
shortcuts: { toggle: { keys: 'mod+comma' } },
}),
SuperscriptPlugin.configure({
shortcuts: { toggle: { keys: 'mod+period' } },
}),
HighlightPlugin.configure({
node: { component: HighlightLeaf },
shortcuts: { toggle: { keys: 'mod+shift+h' } },
}),
KbdPlugin.withComponent(KbdLeaf),
];
添加套件
将套件添加到插件中:
import { createPlateEditor } from 'platejs/react';
import { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';
const editor = createPlateEditor({
plugins: [
// ...其他插件,
...BasicMarksKit,
],
});手动配置
安装
pnpm add @platejs/basic-nodes
添加插件
在创建编辑器时将 StrikethroughPlugin 包含到 Plate 插件数组中。
import { StrikethroughPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件,
StrikethroughPlugin,
],
});配置插件
您可以自定义 StrikethroughPlugin 的键盘快捷键。
import { StrikethroughPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件,
StrikethroughPlugin.configure({
shortcuts: { toggle: { keys: 'mod+shift+x' } },
}),
],
});shortcuts.toggle: 定义切换删除线格式的键盘快捷键
添加工具栏按钮
您可以在工具栏中添加 MarkToolbarButton 来切换删除线格式。
插件
StrikethroughPlugin
删除线文本格式插件。默认渲染为 <s> HTML 元素。
转换方法
tf.strikethrough.toggle
切换所选文本的删除线格式。