跳至正文

文档对应 SoEditor 1.2.1

安装与接入

安装固定版本,然后引入 CMS 入口和样式。把下面的 textarea 放进宿主页面,在 DOM 就绪后挂载。

sh
pnpm add @soeditor/editor@1.2.1
html
<label for="content">文章内容</label>
<textarea id="content" name="content"><p>开始编辑</p></textarea>
ts
import { createClassicEditor } from '@soeditor/editor/cms';
import '@soeditor/editor/cms/styles.css';

下面的挂载函数是经过类型检查的运行代码。调用 await attach() 获取实例。默认入口提供 WYSIWYG;需要源码或保存适配器时使用可选入口。

可运行代码

ts
export async function attach() {
    const host = document.querySelector<HTMLTextAreaElement>('#content');
    if (!host) throw new Error('Missing #content textarea');
    return createClassicEditor(host, { locale: 'zh-CN', minHeight: 280 });
}

此代码使用发布版类型检查;完整导入说明见入口与类型

下一步

运行示例 · 配置参考 · 常见问题

面向网站 CMS 的 HTML 编辑器 · MIT