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.
@@ -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;AAqCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAiE9C;AAED;;GAEG;;;;;;;AACH,wBAKE"}
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"}
@@ -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, '&lt;')
19
+ .replace(/>/g, '&gt;')
20
+ .replace(/"/g, '&quot;')
21
+ .replace(/'/g, '&#39;');
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
- let result = line;
30
- // 1. Comments (do first to avoid highlighting keywords in comments)
31
- result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
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
- });
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 &quot; etc)
47
+ escaped = escaped.replace(/(&quot;[^&]*?&quot;|&#39;[^&]*?&#39;|`[^`]*?`)/g, '<span class="token-string">$1</span>');
37
48
  // 3. Numbers
38
- result = result.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
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
- result = result.replace(regex, '<span class="token-keyword">$1</span>');
53
+ escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
43
54
  });
44
- // 5. Braces, brackets, parentheses
45
- result = result.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
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
- result = result.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
48
- return result || ' ';
58
+ escaped = escaped.replace(/([+\-*/%=&lt;&gt;!&|^~?:])/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, '&amp;')
62
- .replace(/</g, '&lt;')
63
- .replace(/>/g, '&gt;')
64
- .replace(/"/g, '&quot;')
65
- .replace(/'/g, '&#39;');
66
- }
67
67
  /**
68
68
  * Generate CSS for syntax highlighting
69
69
  */
@@ -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, '&amp;')
25
+ .replace(/</g, '&lt;')
26
+ .replace(/>/g, '&gt;')
27
+ .replace(/"/g, '&quot;')
28
+ .replace(/'/g, '&#39;');
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
- let result = line;
50
+ // Escape the raw line first
51
+ let escaped = escapeHtml(line);
39
52
 
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>');
53
+ // Now add spans (on already-escaped text)
43
54
 
44
- // 2. Strings (avoid highlighting keywords in strings)
45
- result = result.replace(/(['"`])(?:(?=(\\?))\2.)*?\1/g, (match) => {
46
- return `<span class="token-string">${escapeHtml(match)}</span>`;
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 &quot; etc)
60
+ escaped = escaped.replace(/(&quot;[^&]*?&quot;|&#39;[^&]*?&#39;|`[^`]*?`)/g, '<span class="token-string">$1</span>');
48
61
 
49
62
  // 3. Numbers
50
- result = result.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
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
- result = result.replace(regex, '<span class="token-keyword">$1</span>');
68
+ escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
56
69
  });
57
70
 
58
- // 5. Braces, brackets, parentheses
59
- result = result.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
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
- result = result.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
75
+ escaped = escaped.replace(/([+\-*/%=&lt;&gt;!&|^~?:])/g, '<span class="token-operator">$1</span>');
63
76
 
64
- return result || ' ';
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, '&amp;')
80
- .replace(/</g, '&lt;')
81
- .replace(/>/g, '&gt;')
82
- .replace(/"/g, '&quot;')
83
- .replace(/'/g, '&#39;');
84
- }
85
-
86
87
  /**
87
88
  * Generate CSS for syntax highlighting
88
89
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juxscript",
3
- "version": "1.1.50",
3
+ "version": "1.1.51",
4
4
  "type": "module",
5
5
  "description": "A JavaScript UX authorship platform",
6
6
  "main": "index.js",