# 读取、替换和撤销 {#editor-instance}

Source: [读取、替换和撤销 | Yurich React 编辑器 API 参考 · Yurich](https://leeyujoo.com/yurich/zh-cn/api/editor-instance/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

```ts
interface EditorInstance {
  getHTML(): string;
  getJSON(): DocumentJSON;
  setHTML(html: string, options?: { history?: boolean }): void;
  readonly history: {
    undo(): void;
    redo(): void;
    canUndo(): boolean;
    canRedo(): boolean;
  };
  subscribe(listener: () => void): () => void;
  readonly el: HTMLElement | null;
}
```

`getHTML()` 读取 HTML，`getJSON()` 返回文档树。`setHTML` 替换整个文档，默认增加一步撤销。`{ history: false }` 清空历史。首次挂载前调用将设置初始内容。

`history` 管理撤销和重做。`subscribe` 监听内容、选区和历史记录变化，并返回取消订阅函数。首次挂载前 `el` 为 `null`。

[提交和恢复 HTML](https://leeyujoo.com/yurich/zh-cn/#save-and-restore-html) · [编辑和历史记录](https://leeyujoo.com/yurich/zh-cn/features/history/)
