juxscript 1.1.51 → 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 +2 -5
- package/lib/utils/codeparser.d.ts.map +1 -1
- package/lib/utils/codeparser.js +19 -36
- package/lib/utils/codeparser.ts +19 -42
- package/package.json +1 -1
|
@@ -8,20 +8,17 @@ export interface ParsedLine {
|
|
|
8
8
|
*/
|
|
9
9
|
declare function escapeHtml(text: string): string;
|
|
10
10
|
/**
|
|
11
|
-
* Parse code into lines
|
|
11
|
+
* Parse code into lines - NO FANCY HIGHLIGHTING, JUST KEYWORDS
|
|
12
12
|
*/
|
|
13
13
|
export declare function parseCode(code: string, language?: string): ParsedLine[];
|
|
14
14
|
/**
|
|
15
|
-
* Render a parsed line
|
|
15
|
+
* Render a parsed line
|
|
16
16
|
*/
|
|
17
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,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;
|
|
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,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
|
* Escape HTML entities
|
|
14
14
|
*/
|
|
@@ -21,7 +21,7 @@ function escapeHtml(text) {
|
|
|
21
21
|
.replace(/'/g, ''');
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Parse code into lines
|
|
24
|
+
* Parse code into lines - NO FANCY HIGHLIGHTING, JUST KEYWORDS
|
|
25
25
|
*/
|
|
26
26
|
export function parseCode(code, language = 'javascript') {
|
|
27
27
|
const lines = code.split('\n');
|
|
@@ -32,34 +32,23 @@ export function parseCode(code, language = 'javascript') {
|
|
|
32
32
|
}));
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Ultra-simple highlighting - JUST keywords, nothing fancy
|
|
36
36
|
*/
|
|
37
37
|
function highlightLine(line) {
|
|
38
38
|
if (!line.trim())
|
|
39
39
|
return ' ';
|
|
40
|
-
// Escape
|
|
41
|
-
let
|
|
42
|
-
//
|
|
43
|
-
// 1. Comments
|
|
44
|
-
escaped = escaped.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
45
|
-
escaped = escaped.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
46
|
-
// 2. Strings (already escaped, so look for " etc)
|
|
47
|
-
escaped = escaped.replace(/("[^&]*?"|'[^&]*?'|`[^`]*?`)/g, '<span class="token-string">$1</span>');
|
|
48
|
-
// 3. Numbers
|
|
49
|
-
escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
50
|
-
// 4. Keywords (only whole words)
|
|
40
|
+
// Escape everything first
|
|
41
|
+
let result = escapeHtml(line);
|
|
42
|
+
// Only highlight standalone keywords (word boundaries)
|
|
51
43
|
KEYWORDS.forEach(keyword => {
|
|
44
|
+
// Match whole words only, case-sensitive
|
|
52
45
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
53
|
-
|
|
46
|
+
result = result.replace(regex, '<span class="token-keyword">$1</span>');
|
|
54
47
|
});
|
|
55
|
-
|
|
56
|
-
escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
57
|
-
// 6. Operators
|
|
58
|
-
escaped = escaped.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
59
|
-
return escaped || ' ';
|
|
48
|
+
return result;
|
|
60
49
|
}
|
|
61
50
|
/**
|
|
62
|
-
* Render a parsed line
|
|
51
|
+
* Render a parsed line
|
|
63
52
|
*/
|
|
64
53
|
export function renderLineWithTokens(parsedLine) {
|
|
65
54
|
return parsedLine.html;
|
|
@@ -69,7 +58,7 @@ export function renderLineWithTokens(parsedLine) {
|
|
|
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;
|
|
@@ -29,7 +29,7 @@ function escapeHtml(text: string): string {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Parse code into lines
|
|
32
|
+
* Parse code into lines - NO FANCY HIGHLIGHTING, JUST KEYWORDS
|
|
33
33
|
*/
|
|
34
34
|
export function parseCode(code: string, language: string = 'javascript'): ParsedLine[] {
|
|
35
35
|
const lines = code.split('\n');
|
|
@@ -42,43 +42,26 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Ultra-simple highlighting - JUST keywords, nothing fancy
|
|
46
46
|
*/
|
|
47
47
|
function highlightLine(line: string): string {
|
|
48
48
|
if (!line.trim()) return ' ';
|
|
49
49
|
|
|
50
|
-
// Escape
|
|
51
|
-
let
|
|
50
|
+
// Escape everything first
|
|
51
|
+
let result = escapeHtml(line);
|
|
52
52
|
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
// 1. Comments
|
|
56
|
-
escaped = escaped.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
57
|
-
escaped = escaped.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
58
|
-
|
|
59
|
-
// 2. Strings (already escaped, so look for " etc)
|
|
60
|
-
escaped = escaped.replace(/("[^&]*?"|'[^&]*?'|`[^`]*?`)/g, '<span class="token-string">$1</span>');
|
|
61
|
-
|
|
62
|
-
// 3. Numbers
|
|
63
|
-
escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
64
|
-
|
|
65
|
-
// 4. Keywords (only whole words)
|
|
53
|
+
// Only highlight standalone keywords (word boundaries)
|
|
66
54
|
KEYWORDS.forEach(keyword => {
|
|
55
|
+
// Match whole words only, case-sensitive
|
|
67
56
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
68
|
-
|
|
57
|
+
result = result.replace(regex, '<span class="token-keyword">$1</span>');
|
|
69
58
|
});
|
|
70
59
|
|
|
71
|
-
|
|
72
|
-
escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
73
|
-
|
|
74
|
-
// 6. Operators
|
|
75
|
-
escaped = escaped.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
76
|
-
|
|
77
|
-
return escaped || ' ';
|
|
60
|
+
return result;
|
|
78
61
|
}
|
|
79
62
|
|
|
80
63
|
/**
|
|
81
|
-
* Render a parsed line
|
|
64
|
+
* Render a parsed line
|
|
82
65
|
*/
|
|
83
66
|
export function renderLineWithTokens(parsedLine: ParsedLine): string {
|
|
84
67
|
return parsedLine.html;
|
|
@@ -89,7 +72,7 @@ export function renderLineWithTokens(parsedLine: ParsedLine): string {
|
|
|
89
72
|
*/
|
|
90
73
|
export function getSyntaxHighlightCSS(): string {
|
|
91
74
|
return `
|
|
92
|
-
/* Simple
|
|
75
|
+
/* Simple Code Highlighting */
|
|
93
76
|
.jux-code {
|
|
94
77
|
font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
|
|
95
78
|
font-size: 14px;
|
|
@@ -110,11 +93,10 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
110
93
|
display: flex;
|
|
111
94
|
align-items: flex-start;
|
|
112
95
|
min-height: 1.6em;
|
|
113
|
-
transition: background-color 0.2s;
|
|
114
96
|
}
|
|
115
97
|
|
|
116
98
|
.jux-code-line:hover {
|
|
117
|
-
background-color: rgba(255, 255, 255, 0.
|
|
99
|
+
background-color: rgba(255, 255, 255, 0.03);
|
|
118
100
|
}
|
|
119
101
|
|
|
120
102
|
.jux-code-line-highlight {
|
|
@@ -144,19 +126,14 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
144
126
|
display: none;
|
|
145
127
|
}
|
|
146
128
|
|
|
147
|
-
/* Token colors */
|
|
148
|
-
.token-keyword {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
.token-punctuation { color: #abb2bf; }
|
|
153
|
-
.token-operator { color: #56b6c2; }
|
|
129
|
+
/* Token colors - JUST KEYWORDS */
|
|
130
|
+
.token-keyword {
|
|
131
|
+
color: #c678dd;
|
|
132
|
+
font-weight: 600;
|
|
133
|
+
}
|
|
154
134
|
`;
|
|
155
135
|
}
|
|
156
136
|
|
|
157
|
-
/**
|
|
158
|
-
* Main parser export
|
|
159
|
-
*/
|
|
160
137
|
export default {
|
|
161
138
|
parse: parseCode,
|
|
162
139
|
renderLine: renderLineWithTokens,
|