@seafile/seafile-editor

中文文档
3.0.48发布于 2026/11/02Apache-2.0CommonJS

SeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in Seafile and SeaTable project.

原始使用文档
文档目录22 节
  1. Markdown editor UI
  2. Integrated markdown editor UI
  3. Simple editor UI
  4. Integrated simple editor UI
  5. Installation
  6. Provide components and functions
  7. Components
  8. Functions
  9. MarkdownEditor usage
  10. Define api
  11. Integrate simple into your own page
  12. Props
  13. SimpleEditor usage
  14. Define api
  15. Integrate simple into your own page
  16. Props
  17. Functions
  18. mdStringToSlate(mdString)
  19. slateToMdString(slateNodes)
  20. processor processor.process(mdString)
  21. 🖥 Environment Support
  22. Modern browsers

sea-markdown-editor

SeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in Seafile and SeaTable project.

Markdown editor UI

markdown editor

Integrated markdown editor UI

An integrated demo. You can customize it according to the style you design.

markdown editor

Simple editor UI

simple editor

Integrated simple editor UI

An integrated demo. You can customize it according to the style you design.

simple editor

Installation

To install via npm:

npm install @seafile/seafile-editor --save

Import the library into your project:

import { MarkdownEditor } from '@seafile/seafile-editor';

Provide components and functions

Components

NameExplain
MarkdownEditorMarkdown rich text editor component
SimpleEditorSimple markdown editor component
MarkdownViewerMarkdown content preview component

Functions

NameExplain
mdStringToSlateConvert markdown strings to the data format used by the editor
slateToMdStringConvert the data format used by the editor to a markdown string
processorConvert markdown string to html format content

MarkdownEditor usage

Define api

import axios from 'axios';

class API {

  getFileContent() {
    const fileUrl = '';
    return axios.get(fileUrl);
  }

  saveFileContent(content) {
    const updateLink = '';
    const formData = new FormData();
    const blob = new Blob([data], { type: 'text/plain' });
    formData.append('file', blob);
    axios.post(updateLink, formData);
  }

  uploadLocalImage(file) {
    const uploadLink = '';
    const formData = new FormData();
    formData.append('file', file);
    return axios.post(uploadLink, formData);
  }

}

const editorApi = new API();

export default editorApi;

Integrate simple into your own page

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Button } from 'reactstrap';
import { MarkdownEditor } from '@seafile/seafile-editor';
import editorApi from './api';

export default function MarkdownEditorDemo() {

  const editorRef = useRef(null);
  const [fileContent, setFileContent] = useState('');
  const [isFetching, setIsFetching] = useState(true);
  const [contentVersion, setContentVersion] = useState(0);

  const mathJaxSource = '';

  useEffect(() => {
    editorApi.getFileContent().then(res => {
      setFileContent(res.data);
      setIsFetching(false);
    });
  }, []);

  const onSave = useCallback(() => {
    const content = editorRef.current.getValue();
     editorApi.saveFileContent(content).then(res => {
      window.alert('Saved successfully')
    });
  }, []);

  const onContentChanged = useCallback(() => {
    setContentVersion(contentVersion + 1);
  }, [contentVersion]);

  return (
    <div className='seafile-editor'>
      <MarkdownEditor
        ref={editorRef}
        isFetching={isFetching}
        value={fileContent}
        initValue={''}
        editorApi={editorApi}
        onSave={onSave}
        onContentChanged={onContentChanged}
        mathJaxSource={mathJaxSource}
      />
    </div>
  );
}

Props

Common props you may want to specify include:

  • ref: A reference to the editor, used to obtain the current content in the editor
    • ref.current.getValue: Get the current markdown string value in the editor
    • ref.current.getSlateValue: Get the value of the current slate data format in the editor
  • isFetching: Whether the value of the editor is being obtained, if the loading effect is displayed while obtaining, and if the acquisition is completed, the corresponding content obtained is displayed in the editor.
  • value: The text content obtained
  • initValue: If value does not exist, a default value can be provided via initValue
  • onSave: When the editor content changes, the onSave callback event is triggered externally. The user can save the document by implementing this callback function.
  • onContentChanged: When the editor content changes, a change event is triggered to facilitate the user to record whether the document
  • mathJaxSource: Supports inserting formulas. If you want to support inserting formulas, please provide a path that can load formula resources. If support is not required, you can ignore this parameter. math-jax document

SimpleEditor usage

Define api

import axios from 'axios';

class API {

  getFileContent() {
    const fileUrl = '';
    return axios.get(fileUrl);
  }

  saveFileContent(content) {
    const updateLink = '';
    const formData = new FormData();
    const blob = new Blob([data], { type: 'text/plain' });
    formData.append('file', blob);
    axios.post(updateLink, formData);
  }

  uploadLocalImage(file) {
    const uploadLink = '';
    const formData = new FormData();
    formData.append('file', file);
    return axios.post(uploadLink, formData);
  }

}

const editorApi = new API();

export default editorApi;

Integrate simple into your own page

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Button } from 'reactstrap';
import { SimpleEditor } from '@seafile/seafile-editor';
import editorApi from './api';

export default function SimpleEditorDemo() {

  const editorRef = useRef(null);
  const [fileContent, setFileContent] = useState('');
  const [isFetching, setIsFetching] = useState(true);
  const [contentVersion, setContentVersion] = useState(0);

  const mathJaxSource = '';

  useEffect(() => {
    editorApi.getFileContent().then(res => {
      setFileContent(res.data);
      setIsFetching(false);
    });
  }, []);

  const onSave = useCallback(() => {
    const content = editorRef.current.getValue();
     editorApi.saveFileContent(content).then(res => {
      window.alert('Saved successfully')
    });
  }, []);

  const onContentChanged = useCallback(() => {
    setContentVersion(contentVersion + 1);
  }, [contentVersion]);

  return (
    <div className='seafile-editor'>
      <SimpleEditor
        ref={editorRef}
        isFetching={isFetching}
        value={fileContent}
        initValue={''}
        editorApi={editorApi}
        onSave={onSave}
        onContentChanged={onContentChanged}
        mathJaxSource={mathJaxSource}
      />
    </div>
  );
}

Props

Common props you may want to specify include:

  • ref: A reference to the editor, used to obtain the current content in the editor
    • ref.current.getValue: Get the current markdown string value in the editor
    • ref.current.getSlateValue: Get the value of the current slate data format in the editor
  • isFetching: Whether the value of the editor is being obtained, if the loading effect is displayed while obtaining, and if the acquisition is completed, the corresponding content obtained is displayed in the editor.
  • value: The text content obtained
  • onSave: When the editor content changes, the onSave callback event is triggered externally. The user can save the document by implementing this callback function.
  • onContentChanged: When the editor content changes, a change event is triggered to facilitate the user to record whether the document
  • mathJaxSource: Supports inserting formulas. If you want to support inserting formulas, please provide a path that can load formula resources. If support is not required, you can ignore this parameter. math-jax document

Functions

mdStringToSlate(mdString)

Convert markdown string to data structure supported by editor (slate)

Params

  • mdString: markdown string

Returns

  Slate nodes

slateToMdString(slateNodes)

Convert editor (slate) supported data structures to markdown string

Params

  • slateNodes: slate nodes

Returns

  Markdown string

processor processor.process(mdString)

Convert markdown string to html

Params

  • mdString: markdown string

Returns

 Promise

Demo

const string = '# Hello, I am first level title'
processor.process(string).then(result => {
  const html = String(result);
  ...
})

🖥 Environment Support

  • Modern browsers

Modern browsers

Edge
Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
Edgefalselast 2 versionsfalse

版本与发布记录

@seafile/seafile-editor 共发布 893 个版本,首次发布于 2018/07/09;过去 12 个月发布了 133 个版本。

版本发布日期距今
3.0.48latest2026/11/021 天前
3.0.472026/09/111 个月前
3.0.462026/09/081 个月前
3.0.452026/07/203 个月前
3.0.442026/07/173 个月前
3.0.43-beta2026/07/173 个月前

其他发布通道:alpha.0 → 2.0.33-alpha.0,alpha.1 → 2.0.33-alpha.1,alpha → 3.0.14-alpha.1,aps → 3.0.30-aps.8,wjk → 3.0.30-wjk.1,aik → 3.0.30-aik.33。

关于 @seafile/seafile-editor 的常见问题

@seafile/seafile-editor 是什么?

seammarkdown编辑器是一个基于slate.js的WYSIWYG Markdown编辑器。它用于海上和海上工程。

如何安装 @seafile/seafile-editor?

在项目目录运行 npm install @seafile/seafile-editor,或使用 pnpm add / yarn add / bun add。

@seafile/seafile-editor 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/seafile__seafile-editor 是否存在。

@seafile/seafile-editor 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@seafile/seafile-editor 可以商用吗?

@seafile/seafile-editor 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@seafile/seafile-editor 还在维护吗?

最新版本 3.0.48 发布于 2026/11/02(1 天前);至今共发布 893 个版本,其中过去 12 个月发布了 133 个;首次发布于 2018/07/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。