1 Star 0 Fork 0

wfyn/vditor-react

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

English version | 简体中文

Vditor for React

Vditor 是由 B3log 开发并开源的面向未来的 Markdown 编辑器。这个项目是它的 React 封装。

安装

npm install vditor-react --save

用法

import ReactDOM from 'react-dom'
import Vditor from 'react-vditor'

ReactDOM.render(
	<Vditor height={700} />, 
	document.getElementById('node')
);

然后在 HTML 文件中加入对应的 div 标签:

<div id="node" />

API

大部分 props 会被作为 options 用于初始化 Vditor 实例。你可以在 这里 查看 Vditor 提供的 API。

特别地,vditor-react 提供了一部分经过封装的 props,如下表所示:

名称 定义 默认值 描述 对应的 Vditor 接口
onInit (text: String) => {} () => {} 在编辑器加载完成后的回调,用于获取编辑器文本的初始值 options.after
onSelect (selection: String, text: String) => {} () => {} 文本选中情况变更时触发的回调,用户获取当前选中的文本(和当前编辑器文本) options.select
onInput (text: String) => {} () => {} 用户输入一段文本后的回调,有一定延迟,且 IME 输入法状态下不会触发 options.input
darkMode Boolean false 是否启用编辑器的暗黑模式 options.theme
disabled Boolean false 是否锁定编辑器区域 disabled() enable()

你还可以继承这一类型并通过 this.editor 访问原始的 Vditor 实例。

示例

demo/ 目录下提供了一个完整的使用范例,利用 React Hooks 实现了跟随系统 Dark Mode 和一键锁定/解锁编辑器的功能。你可以通过如下指令构建这一范例:

npm run dev

然后在 http://127.0.0.1:8081 查看。

MIT License Copyright (c) 2020 stevapple 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.

简介

The React wrapper of Vditor, the next-generation Markdown editor. 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wfyn/vditor-react.git
git@gitee.com:wfyn/vditor-react.git
wfyn
vditor-react
vditor-react
master

搜索帮助