New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@doc-tools/yfm-editor

Package Overview
Dependencies
Maintainers
7
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@doc-tools/yfm-editor

YFM wysiwyg editor

  • 12.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
85
increased by63.46%
Maintainers
7
Weekly downloads
 
Created
Source

@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

Keywords

FAQs

Package last updated on 22 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc