UNPKG

2.24 kBMarkdownView Raw
1# 🎉 Web Studio Code - An Editor Used on the Browser Side.
2
3<a href="https://yelloxing.github.io/npm-downloads/?interval=7&packages=wscode"><img src="https://img.shields.io/npm/dm/wscode.svg" alt="Downloads"></a>
4<a href="https://www.npmjs.com/package/wscode"><img src="https://img.shields.io/npm/v/wscode.svg" alt="Version"></a>
5<a href="https://github.com/yelloxing/Web-Studio-Code/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/wscode.svg" alt="License"></a>
6
7<p align="center"><a href="https://yelloxing.github.io/Web-Studio-Code/Web-Studio-Code.html" target="_blank" rel="noopener noreferrer">
8<img width="400" src="https://yelloxing.github.io/Web-Studio-Code/snipping.png" alt="Web Studio Code"></a></p>
9
10## 如何使用
11
12```js
13import WSCode from 'wscode';
14
15var wscode = new WSCode({
16
17 // 编辑器挂载点(必选)
18 el: document.getElementById('wscode'),
19
20 // 初始化文本(可选)
21 content:"初始化文本内容",
22
23 // 编辑器字体(可选,默认"新宋体")
24 "font-family": string,
25
26 // 编辑器字重(可选,默认600)
27 "font-weight": number,
28
29 // 着色方法(可选,默认不特殊着色)
30 shader:function(textString){
31 return [
32 [{
33 content:"内容",
34 color:"文字颜色"
35 },
36 ...],
37 ...
38 ];
39 },
40
41 // 格式化方法(可选)
42 format:function(textString){
43 return "格式化后的文本";
44 },
45
46 // 设置颜色(可选)
47 color: {
48 background:"#d6d6e4", /*编辑器背景*/
49 text : "#000000", /*文本颜色*/
50 number:"#888484", /*行号颜色*/
51 edit:"#eaeaf1", /*编辑行背景色*/
52 cursor:"#ff0000", /*光标颜色*/
53 },
54
55 // 设置一个tab表示多少个空格(可选,默认4)
56 tabSpace:number
57
58});
59```
60
61返回的wscode里面挂载着后续可控方法:
62
63- 格式化代码
64
65```js
66wscode.format();
67```
68
69- 获取当前编辑器代码
70
71```js
72wscode.valueOf();
73```
74
75## 开源协议
76
77[MIT](https://github.com/yelloxing/Web-Studio-Code/blob/master/LICENSE)
78
79Copyright (c) 2020 走一步 再走一步