Skip to content

Commit be6cb01

Browse files
committed
chore: update readme
1 parent 9e7217f commit be6cb01

File tree

1 file changed

+98
-11
lines changed

1 file changed

+98
-11
lines changed

README.md

Lines changed: 98 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,104 @@
1-
# YFM Editor opensource package
1+
# @doc-tools/yfm-editor · [![npm package](https://img.shields.io/npm/v/@doc-tools/yfm-editor)](https://www.npmjs.com/package/@doc-tools/yfm-editor) [![CI](https://img.shields.io/github/workflow/status/yandex-cloud/yfm-editor/CI/master?label=CI&logo=github)](https://github.com/yandex-cloud/yfm-editor/actions/workflows/ci.yml?query=branch:master) [![storybook](https://img.shields.io/badge/Storybook-deployed-ff4685)](https://preview.yandexcloud.dev/yfm-editor/)
22

3-
## Quick start
3+
[YFM](https://ydocs.tech/) WYSIWYG Editor
44

5-
1. Install package
5+
## Install
66

7-
```
8-
npm install @doc-tools/yfm-editor
9-
```
7+
```shell
8+
npm install @doc-tools/yfm-editor
9+
```
1010

11-
1. Install peer dependecies
11+
Ensure that peer dependencies are installed in your project
1212

13-
```
14-
npm install react react-dom @doc-tools/transform @yandex-cloud/i18n @yandex-cloud/uikit lodash
15-
```
13+
```shell
14+
npm install react@17 react-dom@17 @doc-tools/transform@2 @gravity-ui/uikit@3 lodash@4
15+
```
1616

17-
1. _TBD_
17+
## Usage
18+
19+
```js
20+
import {
21+
createExtension,
22+
YfmEditor,
23+
BasePreset,
24+
BehaviorPreset,
25+
MarkdownBlocksPreset,
26+
MarkdownMarksPreset,
27+
YfmPreset,
28+
} from '@doc-tools/yfm-editor';
29+
30+
const domElem = document.querySelector('#editor');
31+
32+
const editor = new YfmEditor({
33+
domElem,
34+
linkify: true,
35+
allowHTML: false,
36+
extensions: [
37+
createExtension((builder) =>
38+
builder
39+
.use(BasePreset, {})
40+
.use(BehaviorPreset, {})
41+
.use(MarkdownBlocksPreset, {image: false, heading: false})
42+
.use(MarkdownMarksPreset, {})
43+
.use(YfmPreset, {}),
44+
)(),
45+
],
46+
onDocChange: () => {
47+
console.log('The contents of the editor have been changed');
48+
},
49+
});
50+
51+
// Serialize current content in YFM
52+
editor.getValue();
53+
```
54+
55+
### Usage with React
56+
57+
```jsx
58+
import React from 'react';
59+
import {
60+
BasePreset,
61+
BehaviorPreset,
62+
createExtension,
63+
MarkdownBlocksPreset,
64+
MarkdownMarksPreset,
65+
useYfmEditor,
66+
YfmEditorComponent,
67+
YfmPreset,
68+
} from '@doc-tools/yfm-editor';
69+
70+
export function Editor({initialContent}) {
71+
const extensions = React.useMemo(() => {
72+
return [
73+
createExtension((builder) =>
74+
builder
75+
.use(BasePreset, {})
76+
.use(BehaviorPreset, {})
77+
.use(MarkdownBlocksPreset, {image: false, heading: false})
78+
.use(MarkdownMarksPreset, {})
79+
.use(YfmPreset, {}),
80+
)(),
81+
];
82+
}, []);
83+
84+
const editor = useYfmEditor({
85+
linkify: true,
86+
allowHTML: false,
87+
extensions,
88+
initialContent,
89+
});
90+
91+
// Serialize current content in YFM
92+
editor.getValue();
93+
94+
return <YfmEditorComponent autofocus editor={editor} />;
95+
}
96+
```
97+
98+
## Development
99+
100+
To start the dev storybook
101+
102+
```shell
103+
npm run dev
104+
```

0 commit comments

Comments
 (0)