arche-highlight 0.6.3 → 0.7.0
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/ArcheHighlight.js +16 -3
- package/README.md +1 -0
- package/package.json +1 -1
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 (
|
|
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 (
|
|
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))
|
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."`.
|