1 Star 2 Fork 0

theajack / tc-editor

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

tc-editor

stars forks version downloads jsdelivr issue

author license Size TopLang Dependent test

🚀 功能强大,体积小巧,简单易用的代码编辑器

在线体验 | 文档 | 更新日志 | 应用:jui-code | 反馈


[TOC]


前言

tc-editor 是一款 功能强大,体积小巧(包含图标素材和依赖库共 40kb),简单易用的代码编辑器,一行代码便可以生成一个在线的代码编辑器,支持强大的自定义功能配置,多行代码缩进缩退,向vscode看齐的代码风格。

0.快速使用

使用 npm 安装:

npm i tc-editor
<div id='editor'></div>
import TCEditor from 'tc-editor';

new TCEditor({el: '#editor'});

使用 script 标签使用会在window上定义 TCEditor 类:

<div id='editor'></div>
<script src="https://cdn.jsdelivr.net/npm/tc-editor/tc-editor.min.js"></script>
<script>
    new TCEditor({el: '#editor'})
</script>

1.功能

  1. 代码上色,向vscode看齐的代码风格
  2. 多行缩进缩退、字体缩放等快捷键
  3. light 与 dark 模式
  4. 一键复制代码
  5. 自适应宽高、自定义宽高、全屏编写
  6. 强大丰富的 api 与 配置

2 详细使用

2.1 参数配置

new TCEditor(config);

config 是一个参数配置的json对象,具体属性如下:

参数 必选 默认值 类型 备注
el -- Ele/string/HTMLElement 容器
buttons true boolean/string/Array 功能按钮配置
fontSize 16 number 字体大小
theme 'dark' string 编辑器主题,可选值为 'normal','dark'
width 300 string/number
height 200 string/number
code -- string 初始代码
tab '\t' string 缩进的字符串
trim true boolean 是否清空前后的换行符
disabled false boolean 是否启用编辑
fullScreen false boolean 是否全屏显示
lineIndex true boolean 是否显示行序号
onload -- function 渲染完成的回调函数,this 指代 TCEditor对象
onsubmit -- function submit按钮点击的回调函数,this 指代 TCEditor对象,参数为编辑器中的代码内容

注:

  1. 如果 el 元素内部有html内容,则 TCEditor 会将其作为 code 渲染,不过 code配置优先级高于 html 内容
  2. buttons 为 true 或 'all' 表示启用所有功能按钮,false表示不启用功能按钮,为数组表示选择性启用
  3. buttons 为数组时可选值有:'fontSizeUp' | 'fontSizeDown' | 'fullScreen' | 'fix' | 'changeTheme' | 'clearCode' | 'resetCode' | 'copy' | 'submit', 详细含义可以参考 2.2 的api方法说明,其中 submit 按钮仅在含有 onsubmit 参数时才会有效
  4. height与width 为auto时表示自适应代码的显示区域大小,其他值直接渲染为编辑器的样式

2.2 api 方法

let editor = new TCEditor(config);
editor[api](args);

api 方法说明如下:

名称 返回值 参数 备注
clearCode -- -- 清空代码
fix -- -- 修复ios和macos上可能出现的重影问题
resetCode -- -- 重置代码为初始化代码
copy boolean -- 复制代码,返回值表示是否复制成功
changeTheme string? string 切换编辑器主题,可选值为 'normal','dark',无参数表示来回切换
fullScreen boolean? boolean 切换全屏状态,无参数表示来回切换
disable boolean? boolean 切换禁用状态,无参数表示来回切换
fontSize number? number 获取或设置字体大小
fontSizeUp -- number 增大字体
fontSizeDown -- number 减小字体
submit -- -- 提交代码,用户执行参数配置中的onsubmit
code string? string? 获取或设置代码

2.3 静态属性和方法

静态属性:

TCEditor.version; // 版本信息
TCEditor.tool; // easy-dom-util 暴露的工具方法

TCEditor.tool 详情见 easy-dom-util

静态方法:

TCEditor.create(config); // 等价于 new TCEditor(config)

3 应用例子

jui-code

The MIT License (MIT) Copyright (c) 2017 - present theajack <contact@theajack.com> All rights reserved. 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.

简介

Code Editor JavaScript Library 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/theajack/tc-editor.git
git@gitee.com:theajack/tc-editor.git
theajack
tc-editor
tc-editor
master

搜索帮助