docs/(plugins)/(marks)/highlight.cn.mdx
<mark> HTML 元素最快捷添加高亮插件的方式是使用 BasicMarksKit,它包含预配置的 HighlightPlugin 以及其他基础标记及其 Plate UI 组件。
HighlightLeaf: 渲染高亮文本元素将套件添加到你的插件中:
import { createPlateEditor } from 'platejs/react';
import { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';
const editor = createPlateEditor({
plugins: [
// ...其他插件
...BasicMarksKit,
],
});
npm install @platejs/basic-nodes
在创建编辑器时将 HighlightPlugin 包含到 Plate 插件数组中。
import { HighlightPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...其他插件
HighlightPlugin,
],
});
你可以使用自定义组件和快捷键来配置 HighlightPlugin。
import { HighlightPlugin } from '@platejs/basic-nodes/react';
import { createPlateEditor } from 'platejs/react';
import { HighlightLeaf } from '@/components/ui/highlight-node';
const editor = createPlateEditor({
plugins: [
// ...其他插件
HighlightPlugin.configure({
node: { component: HighlightLeaf },
shortcuts: { toggle: { keys: 'mod+shift+h' } },
}),
],
});
node.component: 分配 HighlightLeaf 来渲染高亮文本元素shortcuts.toggle: 定义用于切换高亮格式的键盘快捷键你可以将 MarkToolbarButton 添加到你的工具栏中来切换高亮格式。
HighlightPlugin用于高亮文本格式化的插件。默认渲染为 <mark> HTML 元素。
tf.highlight.toggle切换选中文本的高亮格式。