1 | <p align="center"><a href="https://github.com/yelloxing/Web-Studio-Code" target="_blank" rel="noopener noreferrer">
|
2 | <img width="400" src="https://yelloxing.github.io/Web-Studio-Code/logo.png" alt="Web Studio Code"></a></p>
|
3 |
|
4 | # 🎉 Web Studio Code - An Editor Used on the Browser Side.
|
5 |
|
6 | <p align="center">
|
7 | <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>
|
8 | <a href="https://packagephobia.now.sh/result?p=wscode"><img src="https://packagephobia.now.sh/badge?p=wscode" alt="install size"></a>
|
9 | <a href="https://www.jsdelivr.com/package/npm/wscode"><img src="https://data.jsdelivr.com/v1/package/npm/wscode/badge" alt="CDN"></a>
|
10 | <a href="https://www.npmjs.com/package/wscode"><img src="https://img.shields.io/npm/v/wscode.svg" alt="Version"></a>
|
11 | <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>
|
12 | </p>
|
13 |
|
14 | <p align="center"><a href="https://yelloxing.github.io/Web-Studio-Code/Web-Studio-Code.html" target="_blank" rel="noopener noreferrer">
|
15 | <img width="500" src="https://yelloxing.github.io/Web-Studio-Code/snipping.png" alt="Web Studio Code"></a></p>
|
16 |
|
17 | > 温馨提示:使用过程中,你可以查看 [版本历史](./CHANGELOG) 来了解是否需要升级!
|
18 |
|
19 | > 兼容Chrome、Safari、Edge、Firefox、Opera和IE(9+)等常见浏览器!
|
20 |
|
21 | ## 如何引入
|
22 |
|
23 | 我们推荐你使用npm的方式安装和使用:
|
24 |
|
25 | ```bash
|
26 | npm install --save wscode
|
27 | ```
|
28 |
|
29 | 当然,你也可以通过CDN的方式引入:
|
30 |
|
31 | ```html
|
32 | <script src="https://cdn.jsdelivr.net/npm/wscode@1.7.2/dist/wscode.min.js"></script>
|
33 | ```
|
34 |
|
35 | ## 如何使用
|
36 |
|
37 | ```js
|
38 | import WSCode from 'wscode';
|
39 |
|
40 | var wscode = new WSCode({
|
41 |
|
42 | // 编辑器挂载点(必选)
|
43 | el: document.getElementById('wscode'),
|
44 |
|
45 | // 初始化文本(可选)
|
46 | content:"初始化文本内容",
|
47 |
|
48 | // 编辑器字体(可选,默认"新宋体")
|
49 | "font-family": string,
|
50 |
|
51 | // 编辑器字重(可选,默认600)
|
52 | "font-weight": number,
|
53 |
|
54 | // 着色方法(可选,默认不特殊着色)
|
55 | shader:function(textString, colors){
|
56 | return [
|
57 | [{
|
58 | content:"内容",
|
59 | color:"文字颜色"
|
60 | },
|
61 | ...],
|
62 | ...
|
63 | ];
|
64 | },
|
65 |
|
66 | // 格式化方法(可选)
|
67 | format:function(textString, tabNumber){
|
68 | return "格式化后的文本";
|
69 | },
|
70 |
|
71 | // 设置颜色(可选)
|
72 | color: {
|
73 | background:"#d6d6e4", /*编辑器背景*/
|
74 | text : "#000000", /*文本颜色*/
|
75 | number:"#888484", /*行号颜色*/
|
76 | edit:"#eaeaf1", /*编辑行背景色*/
|
77 | cursor:"#ff0000", /*光标颜色*/
|
78 | select:"#6c6cf1", /*选择背景*/
|
79 | },
|
80 |
|
81 | // 设置一个tab表示多少个空格(可选,默认4)
|
82 | tabSpace:number,
|
83 |
|
84 | // 除了通过传递shader和format的方式实现着色和格式化外
|
85 | // 你还可以使用内置提供的语言来实现
|
86 | // 【特别提醒:shader和format的优先级均高于这里】
|
87 | // (可选)
|
88 | lang:{
|
89 |
|
90 | // 设置语言类型(默认值"normal",表示普通文本,无特殊处理)
|
91 | type:'normal|html|css|javascript|json',
|
92 |
|
93 | // 配置更细节的着色(可选)
|
94 | color:{
|
95 | "annotation": "#6a9955",/*注释颜色*/
|
96 | "border": "#ffffff",/*边界颜色*/
|
97 | "tag": "#1e50b3",/*结点颜色*/
|
98 | "attr": "#1e83b1",/*属性颜色*/
|
99 | "string": "#ac4c1e",/*字符串颜色*/
|
100 | "key": "#ff0000",/*关键字颜色*/
|
101 | }
|
102 | }
|
103 |
|
104 | });
|
105 | ```
|
106 |
|
107 | 返回的wscode里面挂载着后续可控方法:
|
108 |
|
109 | - 格式化代码
|
110 |
|
111 | ```js
|
112 | wscode.format();
|
113 | ```
|
114 |
|
115 | - 获取当前编辑器代码
|
116 |
|
117 | ```js
|
118 | wscode.valueOf();
|
119 | ```
|
120 |
|
121 | ## 开源协议
|
122 |
|
123 | [MIT](https://github.com/yelloxing/Web-Studio-Code/blob/master/LICENSE)
|
124 |
|
125 | Copyright (c) 2020 走一步 再走一步
|