react代码编辑器 react-ace
首先说一下网上其他的编辑器:
轻量级:
1.codeMirror :文档和代码对不上,没有diff功能
github地址:https://github.com/codemirror/CodeMirror
示例代码:https://uiwjs.github.io/react-codemirror/
2.react-code-diff 最近一次维护2018年,直接报错无法使用
重量级:
1.monaco :微软出品,值得信赖
github地址:https://github.com/microsoft/monaco-editor
2.diff2html:也是功能很全的编辑器
官网:https://diff2html.xyz/
gitbub地址:https://github.com/rtfpessoa/diff2html
3.aceEditor:今天的重点
官网:https://ace.c9.io/#nav=about&api=editor
github地址:https://github.com/ajaxorg/ace
aceEditor其他版本
官方的aceEditor是js版的,后续有其他团队陆续出了vue版和react版,是官方的拓展版本,使用可参考官方的文档,其中字段名和方法名都和官方一致,方便使用。
vue版github地址:https://github.com/chairuosen/vue2-ace-editor
react版github地址:https://github.com/securingsincity/react-ace
react版aceEditor
使用方法:
install
npm install react-ace ace-builds
import AceEditor from 'react-ace';
import 'ace-builds/src-noconflict/mode-jsx';// jsx模式的包
import 'ace-builds/src-noconflict/theme-monokai';// monokai的主题样式
import 'ace-builds/src-noconflict/ext-language_tools'; // 代码联想const jsx = `import AceEditor from 'react-ace';
import 'ace-builds/src-noconflict/mode-golang'; // sql模式的包
import 'ace-builds/src-noconflict/mode-jsx';// mysql模式的包`;<AceEditormode='jsx'theme="monokai"name="app_code_editor"fontSize={14}showPrintMarginheight="200px"width="1000px"showGutteronChange={value => {console.log(value); // 输出代码编辑器内值改变后的值}}value={jsx}wrapEnabledhighlightActiveLine //突出活动线enableSnippets //启用代码段setOptions={{enableBasicAutocompletion: true, //启用基本自动完成功能enableLiveAutocompletion: true, //启用实时自动完成功能 (比如:智能代码提示)enableSnippets: true, //启用代码段showLineNumbers: true,tabSize: 2,}}annotations={[{ row: 0, column: 2, type: 'error', text: 'Some error.'}]} // 错误,警告
/>
效果:
diff用法
import { diff as DiffEditor } from "react-ace";const goLang = `package main
import "fmt"func main() {fmt.Println("Hello, 世界")
}`;const goLang1 = `package main
import "fmt"func main() {fmt.Println("Hello, 世界");fmt.Println("Hello, 世界");
}`;
<DiffEditormode='golang'theme="monokai"value={[goLang, `${goLang1};`]}height="1000px"width="1000px"
/>
注意:不定义样式看不见效果,className为:.codeMarker
.codeMarker {background: #fff677;position: absolute;z-index: 20;
}
react代码编辑器 react-ace相关推荐
- react html编辑器,react项目中使用富文本编辑器
安装: cnpm install -D draft-js draftjs-to-html react-draft-wysiwyg // 用来指定商品详情的富文本编辑库 import React, { ...
- 127.0.0.1 zxt.php_php单文件版在线代码编辑器使用方法
这篇文章主要介绍了php单文件版在线代码编辑器,个人感觉相当不错,分享给大家,需要的朋友可以参考下 密码加密方式: * md5(自设密码+$ace) //$ace为cdn镜像地址 使用方法: * 1. ...
- 从0实现react框架,React Fiber架构和Fiber Diff算法
react框架是目前最为流行的前端框架之一,尤其在很多大厂,应用更为广泛.相对于一些mvvm框架,react上手需要一定的技术基础,但掌握后,编码体验和性能是很不错的.react整体思想是函数式编程, ...
- 在线代码编辑器 Codemirror 的轻量级 React 组件
代码编辑器 CodeMirror 的轻量级 React 组件 demo @uiw-react.github.io/react-codem- 特性: ? 自动根据 mode 配置加载 mode 文件. ...
- react html编辑器,在线代码编辑器 Codemirror 的轻量级 React 组件
代码编辑器 CodeMirror 的轻量级 React 组件 demo @uiw-react.github.io/react-codemirror/ 特征:
- react中CodeMirror (代码编辑器)
前言: 实现一个在react项目中页面展示代码编辑器的效果. codemirror: 使用JavaScript为浏览器实现的多功能文本编辑器.codemirror作用:专门用于编辑代码,并带有实现更高 ...
- React基于monaco editor的在线代码编辑器开发
完整项目在这里:monaco-editor-app Monaco Editor App 本仓库用于演示Monoca Editor的用法 运行 node 版本:14.18.1,npm 版本:6.14.1 ...
- react在线浏览doc_CodeMirror代码编辑器(react篇)
简介 CodeMirror 是一款在线的支持语法高亮的代码编辑器,官网地址:https://codemirror.net/ 安装 npm install react-codemirror2 codem ...
- Ace(在线代码编辑器)介绍、使用
介绍 Ace是一个用JavaScript编写的可嵌入代码编辑器.它与Sublime,Vim和TextMate等本机编辑器的功能和性能相匹配.它可以轻松地嵌入任何网页和JavaScript应用程序中. ...
- 使用CodePen编写react代码
开篇题外话: CodePen是一个在线编辑前端代码的网站,对于前端小白来说非常好用,除了可以同时编辑html.css.js之外,可以实时的看到编写网页的样子,真的很方便. CodePen网站链接:ht ...
最新文章
- 企业架构在中国的本地化发展
- oracle数据库单个数据文件的大小限制
- CentOS7.1 KVM虚拟化之虚拟机添加磁盘
- Docker 极简入门教程,傻瓜都能看懂!
- 蓝桥杯-合并石子(java)
- 助力苏州、星火相传,广苏两地微软技术俱乐部交流纪实
- 做了中台就不会死吗?每年至少40%开发资源是被浪费的!
- python sizeof_python 变量作用域 v.__sizeof__() python 深复制 一切皆对象 尽量减少内存消耗 赋值语句的原理...
- 转 - 猴子都能看懂的比特币区块链技术之加密算法
- Datawhale编程学习之排序(3)
- vpp自动化测试报错调试
- c语言许多名字随机抽取名字,怎么用ppt实现一个随机抽取名字的功能
- VBScript教程之一(Hello VBScriopt)
- Python爬虫-selenium爬取网易云歌单
- 读书笔记,《刻意练习》,第四章,黄金标准
- python单词怎么写_python 写的查单词的脚本
- 基本算法总结,力扣题目整理
- 《JSP实用教程(第4版)》第2章学习笔记
- 台灯有必要买AA级的吗?精选专业护眼的国AA级台灯
- 最新版穿越火线游戏识别教程(人工智能yolov5)