-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
111 lines (103 loc) · 3.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* @Description: 剑三宏语法高亮
* @Author: iRuxu
* @Date: 2019-09-01 01:18:34
* @LastEditors: iRuxu
* @LastEditTime: 2019-09-10 07:06:27
*/
import $ from 'jquery'
class JX3_MACRO{
constructor(data){
this.data = data
this.init()
}
init(){
let arrays = this.data.split('\n');
this.lines = [];
for ( let i = 0 ; i < arrays.length ; i++ ){
this.lines.push(this._language(arrays[i]));
}
this.code = '<ol>' + this.lines.join('') + '</ol>'
return
}
_language(strings){
let cmdstring = '';
if ( !/^\#/.test($.trim(strings)) ){
let cmd = strings.indexOf('--')
if ( cmd > -1 ){
cmdstring = strings.substring(cmd);
strings = strings.substring(0, cmd);
if ( $.trim(strings).length === 0 ){
strings = cmdstring;
cmdstring = '';
if ( $.trim(strings).length === 0 ){
strings = '';
}
}
}
}
let tstring = $.trim(strings),
h = '';
if ( /^\#/.test(tstring) ){
var system = /(\s+)?#([^\s]+)\s(.+)/.exec(strings);
var a1 = system[1] ? system[1] : '';
var a2 = system[2];
var a3 = system[3];
h += '<li><pre>' + a1 + '<span class="jx3macro-system macro-system-' + a2.toLowerCase() + '">#' + a2 + '</span> <span class="jx3macro-system-string">' + this._params(a3) + '</span></pre></li>';
}
else if ( /^\-\-/.test(tstring) ){
h += '<li><pre><span class="jx3macro-comment">' + strings + '</span></pre></li>';
}
else{
var keyword = /(\s+)?\/([^\s\[]+)(\s?\[([^\]]+)\])?(\s?(.+))?/.exec(strings);
if ( keyword ){
var b1 = keyword[1] ? keyword[1] : '';
var b2 = keyword[2];
var b3 = keyword[4];
var b4 = keyword[6];
h += '<li><pre>';
h += b1;
h += '<span class="jx3macro-keyword jx3macro-keyword-' + b2.toLowerCase() + '">/' + b2 + '</span>';
if ( keyword[3] ){
h += ' ';
h += '<span class="jx3macro-key">[</span>';
h += '<span class="jx3macro-condition">' + this._condition(b3) + '</span>';
h += '<span class="jx3macro-key">]</span>';
}
if ( keyword[5] ){
h += ' ';
h += '<span class="jx3macro-skill-name">' + this._condition(b4) + '</span>';
}
if ( cmdstring && cmdstring.length > 0 ){
h += ' ';
h += '<span class="jx3macro-comment">' + cmdstring + '</span>';
}
h += '</pre></li>';
}else{
h += '<li><pre>' + strings + ( cmdstring && cmdstring.length > 0 ? cmdstring : '' ) + '</pre></li>';
}
}
return h;
}
_params(s){
return s.replace(/v\_([^\s\<\>\=\&\;\|\(\)\[\]\:\~\,\+\-\%\*\/\!]+)/, '<span class="jx3macro-param">v_$1</span>')
.replace(/\,/g, '<span class="jx3macro-key">,</span>')
.replace(/(tip)(\_\d)?\:/ig, '<span class="jx3macro-key">$1$2:</span>')
.replace(/(icon)(\_\d)?\:/ig, '<span class="jx3macro-key">$1$2:</span>')
}
_condition(s){
let h = '',
keys = ['<', '>', '=', '&', ';', '|', '(', ')', '[', ']', ':', '~', ',', '+', '-', '%', '*', '/', '!'];
for ( let i = 0 ; i < s.length ; i++ ){
let t = s.charAt(i);
if ( keys.indexOf(t) > -1 ){
h += '<span class="jx3macro-key">' + t + '</span>';
}else{
h += t;
}
}
h = h.replace(/(v)\_([^\s\<\>\=\&\;\|\(\)\[\]\:\~\,\+\-\%\*\/\!]+)/ig, '<span class="jx3macro-condition">$1_$2</span>');
return h;
}
}
export default JX3_MACRO;