4 Star 7 Fork 1

Gitee 极速下载 / react-markdown-editor-lite

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/HarryChen0506/react-markdown-editor-lite
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

react-markdown-editor-lite

NPM package NPM downloads MIT License Workflow

English Docs

  • A light-weight(20KB zipped) Markdown editor of React component
  • Supports TypeScript
  • Supports custom markdown parser
  • Full markdown support
  • Supports pluggable function bars
  • Full control over UI
  • Supports image uploading and dragging
  • Supports synced scrolling between editor and preview
  • 一款轻量的基于 React 的 Markdown 编辑器, 压缩后代码只有 20KB
  • 支持 TypeScript
  • 支持自定义 Markdown 解析器
  • 支持常用的 Markdown 编辑功能,如加粗,斜体等等...
  • 支持插件化的功能键
  • 界面可配置, 如只显示编辑区或预览区
  • 支持图片上传或拖拽
  • 支持编辑区和预览区同步滚动

案例

在线案例
https://harrychen0506.github.io/react-markdown-editor-lite/

默认配置

image

可插拔的功能键

image

安装

npm install react-markdown-editor-lite --save
# or
yarn add react-markdown-editor-lite

基本使用

基本使用分为以下几步:

  • 导入 react-markdown-editor-lite
  • 注册插件(如果需要)
  • 初始化任意 Markdown 解析器,例如 markdown-it
  • 开始使用
// 导入React、react-markdown-editor-lite,以及一个你喜欢的Markdown渲染器
import React from 'react';
import MarkdownIt from 'markdown-it';
import MdEditor from 'react-markdown-editor-lite';
// 导入编辑器的样式
import 'react-markdown-editor-lite/lib/index.css';

// 注册插件(如果有的话)
// MdEditor.use(YOUR_PLUGINS_HERE);

// 初始化Markdown解析器
const mdParser = new MarkdownIt(/* Markdown-it options */);

// 完成!
function handleEditorChange({ html, text }) {
  console.log('handleEditorChange', html, text);
}
export default props => {
  return (
    <MdEditor style={{ height: '500px' }} renderHTML={text => mdParser.render(text)} onChange={handleEditorChange} />
  );
};

在 SSR(服务端渲染)中使用

如果你在使用一个服务端渲染框架,例如 Next.js、Gatsby 等,请对编辑器使用客户端渲染。

例如,Next.js 有next/dynamic,Gatsby 有loadable-components

下面是 Next.js 的使用范例:

import dynamic from 'next/dynamic';
import 'react-markdown-editor-lite/lib/index.css';

const MdEditor = dynamic(() => import('react-markdown-editor-lite'), {
  ssr: false,
});

export default function() {
  return <MdEditor style={{ height: '500px' }} renderHTML={/* Render function */} />;
}

与插件一起使用:

import dynamic from 'next/dynamic';
import 'react-markdown-editor-lite/lib/index.css';

const MdEditor = dynamic(
  () => {
    return new Promise(resolve => {
      Promise.all([
        import('react-markdown-editor-lite'),
        import('./my-plugin'),
        /** 按照这样加载更多插件,并在下方 use */
      ]).then(res => {
        res[0].default.use(res[1].default);
        resolve(res[0].default);
      });
    });
  },
  {
    ssr: false,
  },
);

export default function() {
  return <MdEditor style={{ height: '500px' }} renderHTML={/* Render function */} />;
}

完整示例见此

浏览器引入

自 1.1.0 起,你可以在浏览器中使用scriptlink标签直接引入文件,并使用全局变量ReactMarkdownEditorLite

你可以通过 cdnjs jsdelivr unpkg 进行下载。

注意:ReactMarkdownEditorLite(RMEL) 依赖 react,请确保其在 RMEL 之前引入。

例如,使用 webpack 时,你可以在页面中通过script引入 ReactMarkdownEditorLite 的 JS 文件,并在 webpack 配置中写:

externals: {
  react: 'React',
  'react-markdown-editor-lite': 'ReactMarkdownEditorLite'
}

更多示例

主要作者

License

MIT

MIT License Copyright (c) 2019 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一款轻量的基于React的markdown编辑器 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/mirrors/react-markdown-editor-lite.git
git@gitee.com:mirrors/react-markdown-editor-lite.git
mirrors
react-markdown-editor-lite
react-markdown-editor-lite
master

搜索帮助