SeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in Seafile and SeaTable project.
npm install @seafile/seafile-editorSeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in Seafile and SeaTable project.
``bash`
npm install @seafile/seafile-editor --save
Import the library into your project:
`javascript`
import { MarkdownEditor } from '@seafile/seafile-editor';
|Name|Explain|
|-|-|
|MarkdownEditor|Markdown rich text editor component|
|SimpleEditor|Simple markdown editor component|
|MarkdownViewer|Markdown content preview component|
`javascript
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;
`
javascript
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 (
ref={editorRef}
isFetching={isFetching}
value={fileContent}
initValue={''}
editorApi={editorApi}
onSave={onSave}
onContentChanged={onContentChanged}
mathJaxSource={mathJaxSource}
/>
);
}`$3
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
$3
`javascript
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;
`$3
`javascript
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 (
ref={editorRef}
isFetching={isFetching}
value={fileContent}
initValue={''}
editorApi={editorApi}
onSave={onSave}
onContentChanged={onContentChanged}
mathJaxSource={mathJaxSource}
/>
);
}`$3
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
$3
Convert markdown string to data structure supported by editor (slate)Params
* mdString: markdown string
Returns
Slate nodes
$3
Convert editor (slate) supported data structures to markdown stringParams
* slateNodes: slate nodes
Returns
Markdown string
$3
Convert markdown string to htmlParams
* mdString: markdown string
Returns
Promise
Demo
`javascript
const string = '# Hello, I am first level title'
processor.process(string).then(result => {
const html = String(result);
...
})``* Modern browsers
| 
Edge | 
Firefox | 
Chrome | 
Safari |
| --- | --- | --- | --- |
| Edge | false | last 2 versions | false |