@gravity-ui/markdown-editor

中文文档
15.50.0发布于 2026/11/11MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4.5万

Markdown wysiwyg and markup editor

原始使用文档
文档目录14 节
  1. Markdown wysiwyg and markup editor
  2. 🔧 Main features
  3. Install
  4. Required dependencies
  5. Getting started
  6. Development
  7. i18n
  8. Contributing
  9. License
  10. For AI agents
  11. When to use
  12. When not to use
  13. Common pitfalls
  14. Documentation for AI agents

Markdown Editor

@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';

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 editor={editor} />;
}

Read more:

Development

  1. Install Nodejs environment, version is specified in .nvmrc file. We recommend using NVM or a similar tool.
  2. Install pnpm, version is specified in package.json in "packageManager" property.
  3. Install dependencies: pnpm i
  4. Run storybook dev-server: pnpm start

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.

Contributing

License

Distributed under the MIT License. See LICENSE for details.

For AI agents

A dual-mode Markdown editor for React that combines a WYSIWYG mode (ProseMirror) and a raw markup mode (CodeMirror), with support for basic Markdown and YFM.

When to use

  • Editing Markdown/YFM content with a switchable visual (WYSIWYG) and source (markup) view.
  • You need an extensible editor: custom marks, nodes, toolbar items, and extensions (HTML, LaTeX, Mermaid, GPT) via the ProseMirror/CodeMirror engines.
  • Rendering the editor UI: create the instance with useMarkdownEditor and render it with MarkdownEditorView.

When not to use

  • Read-only rendering of Markdown to HTML with no editing — transform it with @diplodoc/transform and render the output instead.
  • Plain multiline text input — use TextArea from @gravity-ui/uikit.
  • Rich-text that is not Markdown/YFM — this editor is Markdown-first.

Common pitfalls

  • It is a hook plus a view, not one component. Create the instance with useMarkdownEditor(...) and pass it to <MarkdownEditorView editor={editor} />; there is no single <MarkdownEditor> you render directly.
  • Read the value via the instance, not a controlled value prop. Call editor.getValue() (e.g. on the submit event) to serialize to Markdown; the editor manages its own state.
  • Peer dependencies are required. Your project must provide @diplodoc/transform, @gravity-ui/uikit, @gravity-ui/components, react, and react-dom — check the peerDependencies in package.json.
  • Styles and i18n come from uikit. Set up theming/styles per the uikit docs and call configure({lang}) from both this package and @gravity-ui/uikit.

Documentation for AI agents

Agent-readable documentation for the installed version is located in node_modules/@gravity-ui/markdown-editor/build/docs/INDEX.md.

版本与发布记录

@gravity-ui/markdown-editor 共发布 163 个版本,首次发布于 2024/06/07;过去 12 个月发布了 39 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
15.50.0latest2026/11/115 天前
15.49.02026/10/2721 天前
15.48.12026/10/021 个月前
15.48.22026/10/021 个月前
15.48.02026/09/301 个月前
15.47.12026/09/291 个月前

其他发布通道:untagged → 14.13.0。

关于 @gravity-ui/markdown-editor 的常见问题

@gravity-ui/markdown-editor 是什么?

Markdown wysiwyg and markup editor

如何安装 @gravity-ui/markdown-editor?

在项目目录运行 npm install @gravity-ui/markdown-editor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:katex(^0.16.9)、react(^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0)、react-dom(^16.14.0 || ^17.0.0 || ^18.0.0 || ^19.0.0)、markdown-it(^13.0.0)、@gravity-ui/uikit(^7.1.0)、@diplodoc/transform(^4.43.0)、@gravity-ui/components(^4.10.0)、@diplodoc/cut-extension(^0.5.0 || ^0.6.1 || ^0.7.1 || ^1.0.0)、@diplodoc/file-extension(^0.2.1)、@diplodoc/tabs-extension(^3.5.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gravity-ui/markdown-editor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gravity-ui/markdown-editor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@gravity-ui/markdown-editor 可以商用吗?

@gravity-ui/markdown-editor 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gravity-ui/markdown-editor 的下载量有多少?

根据 npm 官方下载统计,@gravity-ui/markdown-editor 在 2026/10/17 – 2026/11/15 这 30 天内被下载 44,757 次,日均约 1,492 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gravity-ui/markdown-editor 还在维护吗?

最新版本 15.50.0 发布于 2026/11/11(5 天前);至今共发布 163 个版本,其中过去 12 个月发布了 39 个;首次发布于 2024/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。