npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pingfan.ts/markdown-editor

v1.0.3

Published

基于 codemirror6 的 markdown 编辑器

Downloads

79

Readme

React Markdown Editor

基于 codemirror6 的 markdown 编辑器

特性

  • [X] 支持编辑预览同步滚动(滚动时顶部绝对对齐预览内容),支持光标改变时滚动到光标位置(行对齐)
  • [X] 支持粘贴和拖拽上传图片,可显示上传进度
  • [X] 支持 emoji 表情
  • [X] 插入链接和图片支持快速修改urlalttitle等变量属性(tab 键可跳到下一变量,esc 退出修改)
  • [X] 预览采用 react-markdown 解析,支持语法高亮
  • [X] 支持自定义预览渲染
  • [X] 支持codemirror 扩展

截图

使用文档

安装

npm install -S @pingfan.ts/markdown-editor

使用

import React, { useMemo, useRef, useState } from 'react';
import { EditorView, basicSetup } from '@codemirror/basic-setup';
import Editor, { EditorInstance } from '@pingfan.ts/markdown-editor';
import upload from '@pingfan.ts/markdown-editor/es/plugins/upload';
import scrollSync from '@pingfan.ts/markdown-editor/es/plugins/scroll-sync';
import markdown from './markdown.txt';

export default () => {
  const editorRef = useRef<EditorInstance | null>(null);
  const [value, setValue] = useState<string>(markdown);

  const extensions = useMemo(
    () => [
      basicSetup,
      EditorView.lineWrapping,
      upload({
        url: 'api/attachments/upload',
        allowedTypes: 'image/*',
        transform(res: any) {
          return { url: res.data.url };
        },
      }),
      scrollSync(editorRef),
    ],
    [],
  );

  return (
    <Editor
      ref={editorRef}
      height={300}
      value={value}
      onChange={setValue}
      extensions={extensions}
      storageKey="articles-create"
    />
  );
};

API

Editor

| 属性名 | 描述 | 类型 | 默认值 | | --- | --- | --- | --- | | toolbar | 工具条 | false | { buttons: ToolbarButton[]; } | -- | | editorPreviewEnableFullScreen | 编辑预览启用全屏,一般和 height 搭配使用 | boolean | true | | previewOptions | 预览选项 | PreviewOptions | -- | | storageKey | 自动保存,下次初始化时可恢复上一次保存的内容 | string | -- | | value | 编辑器内容 | string | -- | | height | 高度 | number | string | -- | | minHeight | 最小高度 | number | string | -- | | maxHeight | 最大高度 | number | string | -- | | extensions | codemirror 扩展 | Extension[] | -- | | onChange | 内容变化时的回调 | (value: string) => void | -- | | ref | -- | Ref<EditorInstance> | -- |

PreviewOptions

| 属性名 | 描述 | 类型 | 默认值 | | --- | --- | --- | --- | | render | 自定义渲染 | (markdown: string) => ReactNode | -- | | interval | 刷新间隔 | number | 1000 | | remarkPlugins | remark 插件 | PluggableList | -- | | rehypePlugins | rehype 插件 | PluggableList | -- | | markdownOptions | react-markdown 选项 | Partial<ReactMarkdownOptions> | -- |

EditorInstance

| 名称 | 说明 | 类型 | | --- | --- | --- | | getContainer | 获取编辑器容器DOM | () => HTMLDivElement | null | | getEditorView | 获取 codemirror 实例 | () => EditorView | null | | getToolbar | 获取 Toolbar 实例 | () => ToolbarInstance | null | | getPreview | 获取 Preview 实例 | () => PreviewInstance | null | | getDisplayMode | 获取显示模式 | () => { fullScreen: boolean; preview: boolean; editorPreview: boolean; } | | toggleFullScreen | 全屏切换 | () => void | | togglePreview | 预览切换 | () => void | | toggleEditorPreview | 编辑预览切换 | () => void |

PreviewInstance

| 名称 | 说明 | 类型 | | --- | --- | --- | | getMarkdown | 获取 markdown 内容 | () => string | | setMarkdown | 设置 markdown 内容 | (markdown: string) => void | | debounceSetMarkdown | 消抖设置 markdown 内容 | (markdown: string) => void | | setMarkdownOptions | 设置 react-markdown 选项 | (markdownOptions: Partial<ReactMarkdownOptions>) => void | | getContainer | 获取预览容器DOM | () => HTMLDivElement | null | | getHast | 获取hast | () => Hast |