Giter VIP home page Giter VIP logo

markdown-editor's Introduction

@gravity-ui/markdown-editor · npm package CI Release storybook

Markdown wysiwyg and markup editor

MarkdownEditor is a powerful tool for working with Markdown, which combines WYSIWYG and Markup modes. This means that you can create and edit content in a convenient visual mode, as well as have full control over the markup.

🔧 Main features

  • Support for the basic Markdown and YFM syntax.
  • Extensibility through the use of ProseMirror and CodeMirror engines.
  • The ability to work in WYSIWYG and Markup modes for maximum flexibility.

Install

npm install @gravity-ui/markdown-editor

Required dependencies

Please note that to start using the package, your project must also have the following installed: @diplodoc/transform, react, react-dom, @gravity-ui/uikit, @gravity-ui/components and some others. Check out the peerDependencies section of package.json for accurate information.

Getting started

The markdown editor is supplied as a React hook to create an instance of editor and a component for rendering the view.
To set up styling and theme see UIKit docs.

import React from 'react';
import {useMarkdownEditor, MarkdownEditorView} from '@gravity-ui/markdown-editor';
import {toaster} from '@gravity-ui/uikit/toaster-singleton-react-18';

function Editor({onSubmit}) {
  const editor = useMarkdownEditor({allowHTML: false});

  React.useEffect(() => {
    function submitHandler() {
      // Serialize current content to markdown markup
      const value = editor.getValue();
      onSubmit(value);
    }

    editor.on('submit', submitHandler);
    return () => {
      editor.off('submit', submitHandler);
    };
  }, [onSubmit]);

  return <MarkdownEditorView stickyToolbar autofocus toaster={toaster} editor={editor} />;
}

Read more:

i18n

To set up internationalization, you just need to use the configure:

import {configure} from '@gravity-ui/markdown-editor';

configure({
  lang: 'ru',
});

Don't forget to call configure() from UIKit and other UI libraries.

Development

To start the dev storybook

npm start

markdown-editor's People

Contributors

beliarh avatar burashka avatar d3m1d0v avatar danonechik94 avatar dependabot[bot] avatar gravity-ui-bot avatar isqua avatar makhnatkin avatar rusandorx avatar saxumcordis avatar smsochneg avatar sofiushko avatar teleginzhenya avatar yc-ui-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-editor's Issues

Hardcoded docs link with redirect to diplodoc

There is a tooltip with markdown markup hints and a link to the documentation in the Editor. Currently, the link redirects to the old https://ydocs.tech/ site, which then redirects to the Russian version of the Diplodoc documentation: https://diplodoc.com/docs/ru/syntax/.
It's better to avoid the redirect, and the link should vary depending on the selected interface language.

image
❯ curl -I https://ydocs.tech
HTTP/1.1 302 Moved temporarily
Content-Length: 50
Location: https://diplodoc.com/docs/ru/index-yfm

Steps to Reproduce:

  • Open the Editor.
  • Hover over the settings icon in the top right corner.
  • Hover over the help icon near the Markdown markup text.
  • Check the address of the Documentation link - it will be https://ydocs.tech/.
  • Click the link - you will be redirected to https://diplodoc.com/docs/ru/syntax/.

Expected Behavior:
The link should lead directly to the appropriate version of the documentation based on the selected interface language without redirects.

Actual Behavior:
The link redirects to the old site and then to the Russian version of the documentation.

Possible Solution:
It looks like the link is hardcoded. I suppose it should be moved into keysets.

Client bundle size for client-side application

I use @diplodoc/transform and @gravity-ui/markdown-editor in my client project to display and edit user messages. While working on it I noticed while throttling the internet connection, that the page bundle that contains both of these components takes up 2.4mb gzipped and it takes a long time to load on a throttled connection.

After reviewing the bundle with bundle analyzer, I noticed that lowlight and higlight.js takes up a lot of space in the bundle. Due to the fact that these are optional deps, I removed them, but still, the bundle takes up 1.4mb, although I don't use custom plugins in @diplodoc/transform and use the minimal commonmark preset in @gravity-ui/markdown-editor. In the bundle I see a lot of packages that are not being used (like plugins and table module).

I prepared a sample project here. You can use it to see the lazy-loaded bundle on the /editor page, that takes up 2.4mb.

I believe that both of these libraries can be optimized a bit, so that the size is adequate for a client application. Although most of the bundle is taken up by @diplodoc/transform, some optimizations can be done to the @gravity-ui/markdown-editor as well. Anyway, if someone uses the @gravity-ui/markdown-editor package, the probability of using the @diplodoc/transform in the same project is high.

I created a similar issue in the @diplodoc/transform repo - diplodoc-platform/transform#446

Editable text area height is different for different view modes

Context
The height of the clickable area in the contenteditable element is different for different view modes (or presets).

Steps to reproduce
You can reproduce it in storybook's Presets section:

  • in Zero, CommonMark and Default presets, the only clickable area to start editing is the placeholder
  • in YFM and Full presets you can click anywhere within the components edit area and start editing

Desirable behaviour
All presets have the same behaviour as YFM and Full presets have

Mobile view

Problem

Editor looks ugly on mobile devices. It shows popups under gravity Sheet, example.

Proposal

Adopt editor for mobile devices:

  • move toolbar to keyboard
  • review buttons in toolbar
  • change popups to flat menu

Reference

Notion
image

Help tooltip is hidden under the toolbar on small screens

On small screens help tooltip with Markdown markup is hidden under the toolbar.

image

Steps to Reproduce:

  • Open the Editor on small screen (height <= 400px).
  • Scroll down editor content to switch toolbar into floating mode
  • Hover over the settings icon in the top right corner.
  • Hover over the help icon near the Markdown markup text - top of the tooltip will be hidden under the toolbar

Expected Behavior:
Tooltip will be on top of the toolbar.

Actual Behavior:
Tooltip is under the toolbar.

Possible Solution:
Play with z-index :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.