@doc-tools/yfm-editor
TypeScript icon, indicating that this package has built-in type declarations

12.4.0 • Public • Published

@doc-tools/yfm-editor · npm package CI storybook

YFM WYSIWYG Editor

Preview: https://preview.yandexcloud.dev/yfm-editor/

Install

npm install @doc-tools/yfm-editor

Ensure that peer dependencies are installed in your project

npm install react@17 react-dom@17 @diplodoc/transform@4 @gravity-ui/uikit@5 @gravity-ui/components@2 lodash@4

Usage

import {
    YfmEditor,
    BasePreset,
    BehaviorPreset,
    MarkdownBlocksPreset,
    MarkdownMarksPreset,
    YfmPreset,
} from '@doc-tools/yfm-editor';

const domElem = document.querySelector('#editor');

const editor = new YfmEditor({
    domElem,
    linkify: true,
    allowHTML: false,
    extensions: (builder) =>
        builder
            .use(BasePreset, {})
            .use(BehaviorPreset, {})
            .use(MarkdownBlocksPreset, {image: false, heading: false})
            .use(MarkdownMarksPreset, {})
            .use(YfmPreset, {}),
    onDocChange: () => {
        console.log('The contents of the editor have been changed');
    },
});

// Serialize current content in YFM
editor.getValue();

Usage with React

import React from 'react';
import {
    Extension,
    BasePreset,
    BehaviorPreset,
    MarkdownBlocksPreset,
    MarkdownMarksPreset,
    useYfmEditor,
    YfmEditorComponent,
    YfmPreset,
} from '@doc-tools/yfm-editor';

export function Editor({initialContent}) {
    const extensions = React.useMemo<Extension>(
        () => (builder) =>
            builder
                .use(BasePreset, {})
                .use(BehaviorPreset, {})
                .use(MarkdownBlocksPreset, {image: false, heading: false})
                .use(MarkdownMarksPreset, {})
                .use(YfmPreset, {}),
        [],
    );

    const editor = useYfmEditor({
        linkify: true,
        allowHTML: false,
        extensions,
        initialContent,
    });

    // Serialize current content in YFM
    editor.getValue();

    return <YfmEditorComponent autofocus editor={editor} />;
}

Development

To start the dev storybook

npm run dev

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
12.4.08latest

Version History

VersionDownloads (Last 7 Days)Published
12.4.08
12.3.00
12.2.10
12.2.00
12.1.00
12.0.10
12.0.05
11.0.00
10.2.30
10.2.20
10.2.10
10.2.00
10.1.00
10.0.00
9.3.10
9.3.00
9.2.00
9.1.10
9.1.00
9.0.00
8.2.10
8.2.00
8.1.00
8.0.00
7.2.00
7.1.00
7.0.00
6.7.00
6.6.00
6.5.00
6.4.00
6.3.00
6.2.00
6.1.40
6.1.30
6.1.20
6.1.10
6.1.00
6.0.00
5.6.00
5.5.10
5.5.00
5.4.00
5.3.00
5.2.00
5.1.00
5.0.00
4.5.00
4.4.10
4.4.00
4.3.00
4.2.00
4.1.00
4.0.10
4.0.00
3.7.00
3.6.00
3.5.00
3.4.50
3.4.40
3.4.30
3.4.20
3.4.10
3.4.00
3.3.00
3.2.00
3.1.00
3.0.00
2.1.00
2.0.00
1.2.00
1.1.10
1.1.00
1.0.00
0.1.10
0.1.00

Package Sidebar

Install

npm i @doc-tools/yfm-editor

Weekly Downloads

13

Version

12.4.0

License

MIT

Unpacked Size

2.36 MB

Total Files

2242

Last publish

Collaborators

  • martyanov-av
  • moki
  • yc-ui-robot
  • yfm-team
  • monsterzz
  • buran
  • yndx-birman111