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