juxscript 1.1.50 → 1.1.51
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 +4 -4
- package/lib/utils/codeparser.d.ts.map +1 -1
- package/lib/utils/codeparser.js +25 -25
- package/lib/utils/codeparser.ts +27 -26
- package/package.json +1 -1
|
@@ -3,6 +3,10 @@ export interface ParsedLine {
|
|
|
3
3
|
html: string;
|
|
4
4
|
raw: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Escape HTML entities
|
|
8
|
+
*/
|
|
9
|
+
declare function escapeHtml(text: string): string;
|
|
6
10
|
/**
|
|
7
11
|
* Parse code into lines with simple syntax highlighting
|
|
8
12
|
*/
|
|
@@ -11,10 +15,6 @@ export declare function parseCode(code: string, language?: string): ParsedLine[]
|
|
|
11
15
|
* Render a parsed line (just returns the pre-generated HTML)
|
|
12
16
|
*/
|
|
13
17
|
export declare function renderLineWithTokens(parsedLine: ParsedLine): string;
|
|
14
|
-
/**
|
|
15
|
-
* Escape HTML entities
|
|
16
|
-
*/
|
|
17
|
-
declare function escapeHtml(text: string): string;
|
|
18
18
|
/**
|
|
19
19
|
* Generate CSS for syntax highlighting
|
|
20
20
|
*/
|
|
@@ -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;AAsCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAiE9C;AAED;;GAEG;;;;;;;AACH,wBAKE"}
|
package/lib/utils/codeparser.js
CHANGED
|
@@ -9,6 +9,17 @@ const KEYWORDS = new Set([
|
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
10
|
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
|
|
11
11
|
]);
|
|
12
|
+
/**
|
|
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
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* Parse code into lines with simple syntax highlighting
|
|
14
25
|
*/
|
|
@@ -26,26 +37,26 @@ export function parseCode(code, language = 'javascript') {
|
|
|
26
37
|
function highlightLine(line) {
|
|
27
38
|
if (!line.trim())
|
|
28
39
|
return ' ';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
// Escape the raw line first
|
|
41
|
+
let escaped = escapeHtml(line);
|
|
42
|
+
// Now add spans (on already-escaped text)
|
|
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>');
|
|
37
48
|
// 3. Numbers
|
|
38
|
-
|
|
49
|
+
escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
39
50
|
// 4. Keywords (only whole words)
|
|
40
51
|
KEYWORDS.forEach(keyword => {
|
|
41
52
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
42
|
-
|
|
53
|
+
escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
|
|
43
54
|
});
|
|
44
|
-
// 5. Braces, brackets, parentheses
|
|
45
|
-
|
|
55
|
+
// 5. Braces, brackets, parentheses (these are plain text, not escaped)
|
|
56
|
+
escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
46
57
|
// 6. Operators
|
|
47
|
-
|
|
48
|
-
return
|
|
58
|
+
escaped = escaped.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
59
|
+
return escaped || ' ';
|
|
49
60
|
}
|
|
50
61
|
/**
|
|
51
62
|
* Render a parsed line (just returns the pre-generated HTML)
|
|
@@ -53,17 +64,6 @@ function highlightLine(line) {
|
|
|
53
64
|
export function renderLineWithTokens(parsedLine) {
|
|
54
65
|
return parsedLine.html;
|
|
55
66
|
}
|
|
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
67
|
/**
|
|
68
68
|
* Generate CSS for syntax highlighting
|
|
69
69
|
*/
|
package/lib/utils/codeparser.ts
CHANGED
|
@@ -16,6 +16,18 @@ export interface ParsedLine {
|
|
|
16
16
|
raw: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
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
|
+
|
|
19
31
|
/**
|
|
20
32
|
* Parse code into lines with simple syntax highlighting
|
|
21
33
|
*/
|
|
@@ -35,33 +47,34 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
35
47
|
function highlightLine(line: string): string {
|
|
36
48
|
if (!line.trim()) return ' ';
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
// Escape the raw line first
|
|
51
|
+
let escaped = escapeHtml(line);
|
|
39
52
|
|
|
40
|
-
//
|
|
41
|
-
result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
42
|
-
result = result.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
53
|
+
// Now add spans (on already-escaped text)
|
|
43
54
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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>');
|
|
48
61
|
|
|
49
62
|
// 3. Numbers
|
|
50
|
-
|
|
63
|
+
escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
51
64
|
|
|
52
65
|
// 4. Keywords (only whole words)
|
|
53
66
|
KEYWORDS.forEach(keyword => {
|
|
54
67
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
55
|
-
|
|
68
|
+
escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
|
|
56
69
|
});
|
|
57
70
|
|
|
58
|
-
// 5. Braces, brackets, parentheses
|
|
59
|
-
|
|
71
|
+
// 5. Braces, brackets, parentheses (these are plain text, not escaped)
|
|
72
|
+
escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
60
73
|
|
|
61
74
|
// 6. Operators
|
|
62
|
-
|
|
75
|
+
escaped = escaped.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
63
76
|
|
|
64
|
-
return
|
|
77
|
+
return escaped || ' ';
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
@@ -71,18 +84,6 @@ export function renderLineWithTokens(parsedLine: ParsedLine): string {
|
|
|
71
84
|
return parsedLine.html;
|
|
72
85
|
}
|
|
73
86
|
|
|
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
87
|
/**
|
|
87
88
|
* Generate CSS for syntax highlighting
|
|
88
89
|
*/
|