juxscript 1.1.50 → 1.1.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/codeparser.d.ts +6 -9
- package/lib/utils/codeparser.d.ts.map +1 -1
- package/lib/utils/codeparser.js +29 -46
- package/lib/utils/codeparser.ts +30 -52
- package/package.json +1 -1
|
@@ -4,24 +4,21 @@ export interface ParsedLine {
|
|
|
4
4
|
raw: string;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Escape HTML entities
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
declare function escapeHtml(text: string): string;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Parse code into lines - NO FANCY HIGHLIGHTING, JUST KEYWORDS
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function parseCode(code: string, language?: string): ParsedLine[];
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Render a parsed line
|
|
16
16
|
*/
|
|
17
|
-
declare function
|
|
17
|
+
export declare function renderLineWithTokens(parsedLine: ParsedLine): string;
|
|
18
18
|
/**
|
|
19
19
|
* Generate CSS for syntax highlighting
|
|
20
20
|
*/
|
|
21
21
|
export declare function getSyntaxHighlightCSS(): string;
|
|
22
|
-
/**
|
|
23
|
-
* Main parser export
|
|
24
|
-
*/
|
|
25
22
|
declare const _default: {
|
|
26
23
|
parse: typeof parseCode;
|
|
27
24
|
renderLine: typeof renderLineWithTokens;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;
|
|
1
|
+
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;AAqBD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CA8D9C;;;;;;;AAED,wBAKE"}
|
package/lib/utils/codeparser.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple keyword
|
|
2
|
+
* Simple keyword list
|
|
3
3
|
*/
|
|
4
|
-
const KEYWORDS =
|
|
4
|
+
const KEYWORDS = [
|
|
5
5
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
6
6
|
'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends',
|
|
7
7
|
'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
|
|
8
8
|
'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
10
|
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
|
|
11
|
-
]
|
|
11
|
+
];
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Escape HTML entities
|
|
14
|
+
*/
|
|
15
|
+
function escapeHtml(text) {
|
|
16
|
+
return text
|
|
17
|
+
.replace(/&/g, '&')
|
|
18
|
+
.replace(/</g, '<')
|
|
19
|
+
.replace(/>/g, '>')
|
|
20
|
+
.replace(/"/g, '"')
|
|
21
|
+
.replace(/'/g, ''');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse code into lines - NO FANCY HIGHLIGHTING, JUST KEYWORDS
|
|
14
25
|
*/
|
|
15
26
|
export function parseCode(code, language = 'javascript') {
|
|
16
27
|
const lines = code.split('\n');
|
|
@@ -21,55 +32,33 @@ export function parseCode(code, language = 'javascript') {
|
|
|
21
32
|
}));
|
|
22
33
|
}
|
|
23
34
|
/**
|
|
24
|
-
*
|
|
35
|
+
* Ultra-simple highlighting - JUST keywords, nothing fancy
|
|
25
36
|
*/
|
|
26
37
|
function highlightLine(line) {
|
|
27
38
|
if (!line.trim())
|
|
28
39
|
return ' ';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
result = result.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
33
|
-
// 2. Strings (avoid highlighting keywords in strings)
|
|
34
|
-
result = result.replace(/(['"`])(?:(?=(\\?))\2.)*?\1/g, (match) => {
|
|
35
|
-
return `<span class="token-string">${escapeHtml(match)}</span>`;
|
|
36
|
-
});
|
|
37
|
-
// 3. Numbers
|
|
38
|
-
result = result.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
39
|
-
// 4. Keywords (only whole words)
|
|
40
|
+
// Escape everything first
|
|
41
|
+
let result = escapeHtml(line);
|
|
42
|
+
// Only highlight standalone keywords (word boundaries)
|
|
40
43
|
KEYWORDS.forEach(keyword => {
|
|
44
|
+
// Match whole words only, case-sensitive
|
|
41
45
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
42
46
|
result = result.replace(regex, '<span class="token-keyword">$1</span>');
|
|
43
47
|
});
|
|
44
|
-
|
|
45
|
-
result = result.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
46
|
-
// 6. Operators
|
|
47
|
-
result = result.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
48
|
-
return result || ' ';
|
|
48
|
+
return result;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Render a parsed line
|
|
51
|
+
* Render a parsed line
|
|
52
52
|
*/
|
|
53
53
|
export function renderLineWithTokens(parsedLine) {
|
|
54
54
|
return parsedLine.html;
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Escape HTML entities
|
|
58
|
-
*/
|
|
59
|
-
function escapeHtml(text) {
|
|
60
|
-
return text
|
|
61
|
-
.replace(/&/g, '&')
|
|
62
|
-
.replace(/</g, '<')
|
|
63
|
-
.replace(/>/g, '>')
|
|
64
|
-
.replace(/"/g, '"')
|
|
65
|
-
.replace(/'/g, ''');
|
|
66
|
-
}
|
|
67
56
|
/**
|
|
68
57
|
* Generate CSS for syntax highlighting
|
|
69
58
|
*/
|
|
70
59
|
export function getSyntaxHighlightCSS() {
|
|
71
60
|
return `
|
|
72
|
-
/* Simple
|
|
61
|
+
/* Simple Code Highlighting */
|
|
73
62
|
.jux-code {
|
|
74
63
|
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
75
64
|
font-size: 14px;
|
|
@@ -90,11 +79,10 @@ export function getSyntaxHighlightCSS() {
|
|
|
90
79
|
display: flex;
|
|
91
80
|
align-items: flex-start;
|
|
92
81
|
min-height: 1.6em;
|
|
93
|
-
transition: background-color 0.2s;
|
|
94
82
|
}
|
|
95
83
|
|
|
96
84
|
.jux-code-line:hover {
|
|
97
|
-
background-color: rgba(255, 255, 255, 0.
|
|
85
|
+
background-color: rgba(255, 255, 255, 0.03);
|
|
98
86
|
}
|
|
99
87
|
|
|
100
88
|
.jux-code-line-highlight {
|
|
@@ -124,18 +112,13 @@ export function getSyntaxHighlightCSS() {
|
|
|
124
112
|
display: none;
|
|
125
113
|
}
|
|
126
114
|
|
|
127
|
-
/* Token colors */
|
|
128
|
-
.token-keyword {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
.token-punctuation { color: #abb2bf; }
|
|
133
|
-
.token-operator { color: #56b6c2; }
|
|
115
|
+
/* Token colors - JUST KEYWORDS */
|
|
116
|
+
.token-keyword {
|
|
117
|
+
color: #c678dd;
|
|
118
|
+
font-weight: 600;
|
|
119
|
+
}
|
|
134
120
|
`;
|
|
135
121
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Main parser export
|
|
138
|
-
*/
|
|
139
122
|
export default {
|
|
140
123
|
parse: parseCode,
|
|
141
124
|
renderLine: renderLineWithTokens,
|
package/lib/utils/codeparser.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simple keyword
|
|
2
|
+
* Simple keyword list
|
|
3
3
|
*/
|
|
4
|
-
const KEYWORDS =
|
|
4
|
+
const KEYWORDS = [
|
|
5
5
|
'async', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
6
6
|
'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends',
|
|
7
7
|
'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof',
|
|
8
8
|
'let', 'new', 'return', 'super', 'switch', 'this', 'throw', 'try',
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
10
|
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
|
|
11
|
-
]
|
|
11
|
+
];
|
|
12
12
|
|
|
13
13
|
export interface ParsedLine {
|
|
14
14
|
lineNumber: number;
|
|
@@ -17,7 +17,19 @@ export interface ParsedLine {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Escape HTML entities
|
|
21
|
+
*/
|
|
22
|
+
function escapeHtml(text: string): string {
|
|
23
|
+
return text
|
|
24
|
+
.replace(/&/g, '&')
|
|
25
|
+
.replace(/</g, '<')
|
|
26
|
+
.replace(/>/g, '>')
|
|
27
|
+
.replace(/"/g, '"')
|
|
28
|
+
.replace(/'/g, ''');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Parse code into lines - NO FANCY HIGHLIGHTING, JUST KEYWORDS
|
|
21
33
|
*/
|
|
22
34
|
export function parseCode(code: string, language: string = 'javascript'): ParsedLine[] {
|
|
23
35
|
const lines = code.split('\n');
|
|
@@ -30,65 +42,37 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
/**
|
|
33
|
-
*
|
|
45
|
+
* Ultra-simple highlighting - JUST keywords, nothing fancy
|
|
34
46
|
*/
|
|
35
47
|
function highlightLine(line: string): string {
|
|
36
48
|
if (!line.trim()) return ' ';
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// 1. Comments (do first to avoid highlighting keywords in comments)
|
|
41
|
-
result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
42
|
-
result = result.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
50
|
+
// Escape everything first
|
|
51
|
+
let result = escapeHtml(line);
|
|
43
52
|
|
|
44
|
-
//
|
|
45
|
-
result = result.replace(/(['"`])(?:(?=(\\?))\2.)*?\1/g, (match) => {
|
|
46
|
-
return `<span class="token-string">${escapeHtml(match)}</span>`;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// 3. Numbers
|
|
50
|
-
result = result.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
51
|
-
|
|
52
|
-
// 4. Keywords (only whole words)
|
|
53
|
+
// Only highlight standalone keywords (word boundaries)
|
|
53
54
|
KEYWORDS.forEach(keyword => {
|
|
55
|
+
// Match whole words only, case-sensitive
|
|
54
56
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
55
57
|
result = result.replace(regex, '<span class="token-keyword">$1</span>');
|
|
56
58
|
});
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
result = result.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
60
|
-
|
|
61
|
-
// 6. Operators
|
|
62
|
-
result = result.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
63
|
-
|
|
64
|
-
return result || ' ';
|
|
60
|
+
return result;
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
/**
|
|
68
|
-
* Render a parsed line
|
|
64
|
+
* Render a parsed line
|
|
69
65
|
*/
|
|
70
66
|
export function renderLineWithTokens(parsedLine: ParsedLine): string {
|
|
71
67
|
return parsedLine.html;
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
/**
|
|
75
|
-
* Escape HTML entities
|
|
76
|
-
*/
|
|
77
|
-
function escapeHtml(text: string): string {
|
|
78
|
-
return text
|
|
79
|
-
.replace(/&/g, '&')
|
|
80
|
-
.replace(/</g, '<')
|
|
81
|
-
.replace(/>/g, '>')
|
|
82
|
-
.replace(/"/g, '"')
|
|
83
|
-
.replace(/'/g, ''');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
70
|
/**
|
|
87
71
|
* Generate CSS for syntax highlighting
|
|
88
72
|
*/
|
|
89
73
|
export function getSyntaxHighlightCSS(): string {
|
|
90
74
|
return `
|
|
91
|
-
/* Simple
|
|
75
|
+
/* Simple Code Highlighting */
|
|
92
76
|
.jux-code {
|
|
93
77
|
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
94
78
|
font-size: 14px;
|
|
@@ -109,11 +93,10 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
109
93
|
display: flex;
|
|
110
94
|
align-items: flex-start;
|
|
111
95
|
min-height: 1.6em;
|
|
112
|
-
transition: background-color 0.2s;
|
|
113
96
|
}
|
|
114
97
|
|
|
115
98
|
.jux-code-line:hover {
|
|
116
|
-
background-color: rgba(255, 255, 255, 0.
|
|
99
|
+
background-color: rgba(255, 255, 255, 0.03);
|
|
117
100
|
}
|
|
118
101
|
|
|
119
102
|
.jux-code-line-highlight {
|
|
@@ -143,19 +126,14 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
143
126
|
display: none;
|
|
144
127
|
}
|
|
145
128
|
|
|
146
|
-
/* Token colors */
|
|
147
|
-
.token-keyword {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
.token-punctuation { color: #abb2bf; }
|
|
152
|
-
.token-operator { color: #56b6c2; }
|
|
129
|
+
/* Token colors - JUST KEYWORDS */
|
|
130
|
+
.token-keyword {
|
|
131
|
+
color: #c678dd;
|
|
132
|
+
font-weight: 600;
|
|
133
|
+
}
|
|
153
134
|
`;
|
|
154
135
|
}
|
|
155
136
|
|
|
156
|
-
/**
|
|
157
|
-
* Main parser export
|
|
158
|
-
*/
|
|
159
137
|
export default {
|
|
160
138
|
parse: parseCode,
|
|
161
139
|
renderLine: renderLineWithTokens,
|