arche-highlight 0.6.3 → 0.7.1

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.
@@ -41,6 +41,7 @@ function parseJavaScript(text) {
41
41
 
42
42
  let index = 0
43
43
  let term = ""
44
+ let isShebangInterpreterDirective = false
44
45
  let isSingleLineComment = false
45
46
  let isMultiLineComment = false
46
47
  let isNumber = false
@@ -54,7 +55,11 @@ function parseJavaScript(text) {
54
55
  while (index < text.length) {
55
56
  let c = text[index]
56
57
 
57
- if (isSingleLineComment && c === "\n") {
58
+ if (isShebangInterpreterDirective && c === "\n") {
59
+ isShebangInterpreterDirective = false
60
+ parsedElements.push(Span({ class: "shebang-interpreter-directive" }, term))
61
+ term = ""
62
+ } else if (isSingleLineComment && c === "\n") {
58
63
  isSingleLineComment = false
59
64
  parsedElements.push(Span({ class: "comment" }, term))
60
65
  term = ""
@@ -120,7 +125,10 @@ function parseJavaScript(text) {
120
125
  break
121
126
  }
122
127
 
123
- if (isSingleLineComment) {
128
+ if (isShebangInterpreterDirective) {
129
+ term += c
130
+ index += 1
131
+ } else if (isSingleLineComment) {
124
132
  term += c
125
133
  index += 1
126
134
  } else if (isMultiLineComment) {
@@ -163,6 +171,10 @@ function parseJavaScript(text) {
163
171
  term += c
164
172
  index += 1
165
173
  }
174
+ } else if (c === "#" && text[index + 1] === "!") {
175
+ isShebangInterpreterDirective = true
176
+ term += c
177
+ index += 1
166
178
  } else if (c === "/" && text[index + 1] === "/") {
167
179
  isSingleLineComment = true
168
180
  term += c
@@ -320,6 +332,8 @@ function parseJavaScript(text) {
320
332
  if (term.length > 0) {
321
333
  if (isSingleLineComment) {
322
334
  parsedElements.push(Span({ class: "comment" }, term))
335
+ } else if (isShebangInterpreterDirective) {
336
+ parsedElements.push(Span({ class: "shebang-interpreter-directive" }, term))
323
337
  } else if (isNumber) {
324
338
  if (term[term.length - 1] === "n") {
325
339
  parsedElements.push(Span({ class: "bigint" }, term))
package/ArcheHighlight.js CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  (function (root, ArcheHighlight) {
6
6
  if (typeof module == 'object') (module.exports = ArcheHighlight) // CommonJS
7
- else if (typeof define == 'function') define(() => ArcheHighlight) // AMD
8
7
  else (root.ArcheHighlight = ArcheHighlight) // Browser
9
8
  }(typeof globalThis == 'object' ? globalThis : this, (function () { 'use strict'
10
9
 
@@ -47,6 +46,7 @@ function parseJavaScript(text) {
47
46
 
48
47
  let index = 0
49
48
  let term = ""
49
+ let isShebangInterpreterDirective = false
50
50
  let isSingleLineComment = false
51
51
  let isMultiLineComment = false
52
52
  let isNumber = false
@@ -60,7 +60,11 @@ function parseJavaScript(text) {
60
60
  while (index < text.length) {
61
61
  let c = text[index]
62
62
 
63
- if (isSingleLineComment && c === "\n") {
63
+ if (isShebangInterpreterDirective && c === "\n") {
64
+ isShebangInterpreterDirective = false
65
+ parsedElements.push(Span({ class: "shebang-interpreter-directive" }, term))
66
+ term = ""
67
+ } else if (isSingleLineComment && c === "\n") {
64
68
  isSingleLineComment = false
65
69
  parsedElements.push(Span({ class: "comment" }, term))
66
70
  term = ""
@@ -126,7 +130,10 @@ function parseJavaScript(text) {
126
130
  break
127
131
  }
128
132
 
129
- if (isSingleLineComment) {
133
+ if (isShebangInterpreterDirective) {
134
+ term += c
135
+ index += 1
136
+ } else if (isSingleLineComment) {
130
137
  term += c
131
138
  index += 1
132
139
  } else if (isMultiLineComment) {
@@ -169,6 +176,10 @@ function parseJavaScript(text) {
169
176
  term += c
170
177
  index += 1
171
178
  }
179
+ } else if (c === "#" && text[index + 1] === "!") {
180
+ isShebangInterpreterDirective = true
181
+ term += c
182
+ index += 1
172
183
  } else if (c === "/" && text[index + 1] === "/") {
173
184
  isSingleLineComment = true
174
185
  term += c
@@ -326,6 +337,8 @@ function parseJavaScript(text) {
326
337
  if (term.length > 0) {
327
338
  if (isSingleLineComment) {
328
339
  parsedElements.push(Span({ class: "comment" }, term))
340
+ } else if (isShebangInterpreterDirective) {
341
+ parsedElements.push(Span({ class: "shebang-interpreter-directive" }, term))
329
342
  } else if (isNumber) {
330
343
  if (term[term.length - 1] === "n") {
331
344
  parsedElements.push(Span({ class: "bigint" }, term))
@@ -41,6 +41,7 @@ function parseJavaScript(text) {
41
41
 
42
42
  let index = 0
43
43
  let term = ""
44
+ let isShebangInterpreterDirective = false
44
45
  let isSingleLineComment = false
45
46
  let isMultiLineComment = false
46
47
  let isNumber = false
@@ -54,7 +55,11 @@ function parseJavaScript(text) {
54
55
  while (index < text.length) {
55
56
  let c = text[index]
56
57
 
57
- if (isSingleLineComment && c === "\n") {
58
+ if (isShebangInterpreterDirective && c === "\n") {
59
+ isShebangInterpreterDirective = false
60
+ parsedElements.push(Span({ class: "shebang-interpreter-directive" }, term))
61
+ term = ""
62
+ } else if (isSingleLineComment && c === "\n") {
58
63
  isSingleLineComment = false
59
64
  parsedElements.push(Span({ class: "comment" }, term))
60
65
  term = ""
@@ -120,7 +125,10 @@ function parseJavaScript(text) {
120
125
  break
121
126
  }
122
127
 
123
- if (isSingleLineComment) {
128
+ if (isShebangInterpreterDirective) {
129
+ term += c
130
+ index += 1
131
+ } else if (isSingleLineComment) {
124
132
  term += c
125
133
  index += 1
126
134
  } else if (isMultiLineComment) {
@@ -163,6 +171,10 @@ function parseJavaScript(text) {
163
171
  term += c
164
172
  index += 1
165
173
  }
174
+ } else if (c === "#" && text[index + 1] === "!") {
175
+ isShebangInterpreterDirective = true
176
+ term += c
177
+ index += 1
166
178
  } else if (c === "/" && text[index + 1] === "/") {
167
179
  isSingleLineComment = true
168
180
  term += c
@@ -320,6 +332,8 @@ function parseJavaScript(text) {
320
332
  if (term.length > 0) {
321
333
  if (isSingleLineComment) {
322
334
  parsedElements.push(Span({ class: "comment" }, term))
335
+ } else if (isShebangInterpreterDirective) {
336
+ parsedElements.push(Span({ class: "shebang-interpreter-directive" }, term))
323
337
  } else if (isNumber) {
324
338
  if (term[term.length - 1] === "n") {
325
339
  parsedElements.push(Span({ class: "bigint" }, term))
package/README.md CHANGED
@@ -73,6 +73,7 @@ Return:
73
73
 
74
74
  ### JavaScript Classes
75
75
  The following JavaScript classes are added to the code as `span` elements of the parsed React Element or HTML:
76
+ * `shebang-interpreter-directive` - an interpreter directive at the beginning of a script starting with the shebang (`#!`) that instructs the loader of the script to execute the specified interpreter, for example `#!/usr/bin/env node`.
76
77
  * `comment` - single line (`//`) or multi-line comments (`/* */`).
77
78
  * `number` - numbers, for example `1`, `0`, `2.5`, `-1`, `100`.
78
79
  * `string` - strings, for example `"a"`, `'a'`, `"This is a string."`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arche-highlight",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "description": "Syntax highlighting for vanilla microfrontends",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",