• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

react 代码编辑器-react-ace

武飞扬头像
咕噜咕噜的车轮向前
帮助1

最近在做react项目,需要一个代码编辑器的功能,之前使用codemirror,发现使用起来不太好用,文档也不全,最后决定使用AceEditor

github地址:GitHub - securingsincity/react-ace: React Ace Component

安装:npm install react-ace ace-builds

使用:

  1.  
    import AceEditor from "react-ace";
  2.  
     
  3.  
    import "ace-builds/src-noconflict/mode-java";
  4.  
    import "ace-builds/src-noconflict/theme-github";
  5.  
    import "ace-builds/src-noconflict/ext-language_tools";
  6.  
     
  7.  
    function onChange(newValue) {
  8.  
    console.log("change", newValue);
  9.  
    }
  10.  
     
  11.  
    // Render editor
  12.  
     
  13.  
    <AceEditor
  14.  
    mode="java"
  15.  
    theme="github"
  16.  
    onChange={onChange}
  17.  
    name="UNIQUE_ID_OF_DIV"
  18.  
    editorProps={{ $blockScrolling: true }}
  19.  
    />
学新通

非常方便。

如果是只要代码高亮,不需要编辑的功能,可以使用react-syntax-highlighter

github连接:https://github.com/react-syntax-highlighter/react-syntax-highlighter

用法:

  1.  
    import SyntaxHighlighter from 'react-syntax-highlighter';
  2.  
    import { tomorrow } from 'react-syntax-highlighter/dist/esm/styles/hljs'; // 主题
  3.  
     
  4.  
     
  5.  
     
  6.  
     
  7.  
    <SyntaxHighlighter
  8.  
    language="yaml" // 高亮的语言我选择yaml可以选择其他的例如javasc等
  9.  
    style={tomorrow}
  10.  
    showLineNumbers
  11.  
    customStyle={{height:'60vh',overflow:'auto'}}
  12.  
    >
  13.  
    {logData}
  14.  
    </SyntaxHighlighter>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfhhci
系列文章
更多 icon
同类精品
更多 icon
继续加载