arche-highlight 0.6.2 → 0.6.3
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.es.js +20 -31
- package/ArcheHighlight.js +1 -1
- package/ArcheHighlight.mjs +20 -31
- package/README.md +8 -0
- package/package.json +1 -1
package/ArcheHighlight.es.js
CHANGED
|
@@ -6,12 +6,6 @@ function testOperatorSymbol(c) {
|
|
|
6
6
|
return c === "+" || c === "-" || c === "*" || c === "/" || c === "=" || c === "&" || c === "|" || c === "<" || c === ">" || c === "~" || c === "^" || c === "!" || c === "?" || c === ":"
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
// testComment(term string) -> boolean
|
|
10
|
-
function testComment(term) {
|
|
11
|
-
return (term[0] === "/" && term[1] === "/")
|
|
12
|
-
|| (term[0] === "/" && term[1] === "*")
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
// pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
|
|
16
10
|
function pushWordTerm(parsedElements, term, index, text) {
|
|
17
11
|
if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
|
|
@@ -99,21 +93,21 @@ function parseJavaScript(text) {
|
|
|
99
93
|
parsedElements.push(Span({ class: "operator" }, term))
|
|
100
94
|
}
|
|
101
95
|
term = ""
|
|
102
|
-
} else if (isStringSingleQuote && c === "'") {
|
|
96
|
+
} else if (isStringSingleQuote && c === "'" && term[term.length - 1] !== "\\") {
|
|
103
97
|
isStringSingleQuote = false
|
|
104
98
|
term += c
|
|
105
99
|
index += 1
|
|
106
100
|
c = text[index]
|
|
107
101
|
parsedElements.push(Span({ class: "string" }, term))
|
|
108
102
|
term = ""
|
|
109
|
-
} else if (isStringDoubleQuote && c === "\"") {
|
|
103
|
+
} else if (isStringDoubleQuote && c === "\"" && term[term.length - 1] !== "\\") {
|
|
110
104
|
isStringDoubleQuote = false
|
|
111
105
|
term += c
|
|
112
106
|
index += 1
|
|
113
107
|
c = text[index]
|
|
114
108
|
parsedElements.push(Span({ class: "string" }, term))
|
|
115
109
|
term = ""
|
|
116
|
-
} else if (isTemplateLiteral && c === "`") {
|
|
110
|
+
} else if (isTemplateLiteral && c === "`" && term[term.length - 1] !== "\\") {
|
|
117
111
|
isTemplateLiteral = false
|
|
118
112
|
term += c
|
|
119
113
|
index += 1
|
|
@@ -122,6 +116,10 @@ function parseJavaScript(text) {
|
|
|
122
116
|
term = ""
|
|
123
117
|
}
|
|
124
118
|
|
|
119
|
+
if (index == text.length) {
|
|
120
|
+
break
|
|
121
|
+
}
|
|
122
|
+
|
|
125
123
|
if (isSingleLineComment) {
|
|
126
124
|
term += c
|
|
127
125
|
index += 1
|
|
@@ -157,6 +155,7 @@ function parseJavaScript(text) {
|
|
|
157
155
|
term = ""
|
|
158
156
|
index += 1
|
|
159
157
|
} else {
|
|
158
|
+
term += templateVariable
|
|
160
159
|
term += c
|
|
161
160
|
index += 1
|
|
162
161
|
}
|
|
@@ -187,16 +186,6 @@ function parseJavaScript(text) {
|
|
|
187
186
|
isOperator = true
|
|
188
187
|
term = c
|
|
189
188
|
index += 1
|
|
190
|
-
} else if (c === ":") {
|
|
191
|
-
parsedElements.push(term)
|
|
192
|
-
if (isTernaryOperator) {
|
|
193
|
-
parsedElements.push(Span({ class: "operator" }, term))
|
|
194
|
-
isTernaryOperator = false
|
|
195
|
-
} else {
|
|
196
|
-
parsedElements.push(Span({ class: "object-colon" }, c))
|
|
197
|
-
}
|
|
198
|
-
term = ""
|
|
199
|
-
index += 1
|
|
200
189
|
} else if (term.length == 0 && c === "'") {
|
|
201
190
|
isStringSingleQuote = true
|
|
202
191
|
term += c
|
|
@@ -218,7 +207,7 @@ function parseJavaScript(text) {
|
|
|
218
207
|
parsedElements.push(c)
|
|
219
208
|
term = ""
|
|
220
209
|
index += 1
|
|
221
|
-
} else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of") {
|
|
210
|
+
} else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of" || term == "from") {
|
|
222
211
|
parsedElements.push(Span({ class: "keyword" }, term))
|
|
223
212
|
parsedElements.push(c)
|
|
224
213
|
term = ""
|
|
@@ -229,20 +218,13 @@ function parseJavaScript(text) {
|
|
|
229
218
|
parsedElements.push(c)
|
|
230
219
|
term = ""
|
|
231
220
|
index += 1
|
|
232
|
-
} else if (
|
|
233
|
-
parsedElements.push(Span({ class: "number" }, term))
|
|
234
|
-
parsedElements.push(c)
|
|
235
|
-
term = ""
|
|
236
|
-
index += 1
|
|
237
|
-
}
|
|
238
|
-
else if (isFunctionDeclaration) {
|
|
221
|
+
} else if (isFunctionDeclaration) {
|
|
239
222
|
isFunctionDeclaration = false
|
|
240
223
|
parsedElements.push(Span({ class: "function-name" }, term))
|
|
241
224
|
parsedElements.push(c)
|
|
242
225
|
term = ""
|
|
243
226
|
index += 1
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
227
|
+
} else {
|
|
246
228
|
if (term.length > 0) {
|
|
247
229
|
index = pushWordTerm(parsedElements, term, index, text)
|
|
248
230
|
c = text[index]
|
|
@@ -273,8 +255,7 @@ function parseJavaScript(text) {
|
|
|
273
255
|
parsedElements.push(Span({ class: "spread-operator" }, term))
|
|
274
256
|
}
|
|
275
257
|
term = ""
|
|
276
|
-
}
|
|
277
|
-
else if (c === "(") {
|
|
258
|
+
} else if (c === "(") {
|
|
278
259
|
if (term === "") {
|
|
279
260
|
// skip
|
|
280
261
|
} else if (term == "require" || term == "isNaN") {
|
|
@@ -339,6 +320,14 @@ function parseJavaScript(text) {
|
|
|
339
320
|
if (term.length > 0) {
|
|
340
321
|
if (isSingleLineComment) {
|
|
341
322
|
parsedElements.push(Span({ class: "comment" }, term))
|
|
323
|
+
} else if (isNumber) {
|
|
324
|
+
if (term[term.length - 1] === "n") {
|
|
325
|
+
parsedElements.push(Span({ class: "bigint" }, term))
|
|
326
|
+
} else if (term.includes("n")) {
|
|
327
|
+
parsedElements.push(term)
|
|
328
|
+
} else {
|
|
329
|
+
parsedElements.push(Span({ class: "number" }, term))
|
|
330
|
+
}
|
|
342
331
|
} else {
|
|
343
332
|
pushWordTerm(parsedElements, term, index, text)
|
|
344
333
|
}
|
package/ArcheHighlight.js
CHANGED
|
@@ -213,7 +213,7 @@ function parseJavaScript(text) {
|
|
|
213
213
|
parsedElements.push(c)
|
|
214
214
|
term = ""
|
|
215
215
|
index += 1
|
|
216
|
-
} else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of") {
|
|
216
|
+
} else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of" || term == "from") {
|
|
217
217
|
parsedElements.push(Span({ class: "keyword" }, term))
|
|
218
218
|
parsedElements.push(c)
|
|
219
219
|
term = ""
|
package/ArcheHighlight.mjs
CHANGED
|
@@ -6,12 +6,6 @@ function testOperatorSymbol(c) {
|
|
|
6
6
|
return c === "+" || c === "-" || c === "*" || c === "/" || c === "=" || c === "&" || c === "|" || c === "<" || c === ">" || c === "~" || c === "^" || c === "!" || c === "?" || c === ":"
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
// testComment(term string) -> boolean
|
|
10
|
-
function testComment(term) {
|
|
11
|
-
return (term[0] === "/" && term[1] === "/")
|
|
12
|
-
|| (term[0] === "/" && term[1] === "*")
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
// pushWordTerm(parsedElements Array<object|string>, term string, index number, text string) -> ()
|
|
16
10
|
function pushWordTerm(parsedElements, term, index, text) {
|
|
17
11
|
if (term == "process" || term == "require" || term == "console" || term == "window" || term == "global" || term == "globalThis" || term == "isNaN") {
|
|
@@ -99,21 +93,21 @@ function parseJavaScript(text) {
|
|
|
99
93
|
parsedElements.push(Span({ class: "operator" }, term))
|
|
100
94
|
}
|
|
101
95
|
term = ""
|
|
102
|
-
} else if (isStringSingleQuote && c === "'") {
|
|
96
|
+
} else if (isStringSingleQuote && c === "'" && term[term.length - 1] !== "\\") {
|
|
103
97
|
isStringSingleQuote = false
|
|
104
98
|
term += c
|
|
105
99
|
index += 1
|
|
106
100
|
c = text[index]
|
|
107
101
|
parsedElements.push(Span({ class: "string" }, term))
|
|
108
102
|
term = ""
|
|
109
|
-
} else if (isStringDoubleQuote && c === "\"") {
|
|
103
|
+
} else if (isStringDoubleQuote && c === "\"" && term[term.length - 1] !== "\\") {
|
|
110
104
|
isStringDoubleQuote = false
|
|
111
105
|
term += c
|
|
112
106
|
index += 1
|
|
113
107
|
c = text[index]
|
|
114
108
|
parsedElements.push(Span({ class: "string" }, term))
|
|
115
109
|
term = ""
|
|
116
|
-
} else if (isTemplateLiteral && c === "`") {
|
|
110
|
+
} else if (isTemplateLiteral && c === "`" && term[term.length - 1] !== "\\") {
|
|
117
111
|
isTemplateLiteral = false
|
|
118
112
|
term += c
|
|
119
113
|
index += 1
|
|
@@ -122,6 +116,10 @@ function parseJavaScript(text) {
|
|
|
122
116
|
term = ""
|
|
123
117
|
}
|
|
124
118
|
|
|
119
|
+
if (index == text.length) {
|
|
120
|
+
break
|
|
121
|
+
}
|
|
122
|
+
|
|
125
123
|
if (isSingleLineComment) {
|
|
126
124
|
term += c
|
|
127
125
|
index += 1
|
|
@@ -157,6 +155,7 @@ function parseJavaScript(text) {
|
|
|
157
155
|
term = ""
|
|
158
156
|
index += 1
|
|
159
157
|
} else {
|
|
158
|
+
term += templateVariable
|
|
160
159
|
term += c
|
|
161
160
|
index += 1
|
|
162
161
|
}
|
|
@@ -187,16 +186,6 @@ function parseJavaScript(text) {
|
|
|
187
186
|
isOperator = true
|
|
188
187
|
term = c
|
|
189
188
|
index += 1
|
|
190
|
-
} else if (c === ":") {
|
|
191
|
-
parsedElements.push(term)
|
|
192
|
-
if (isTernaryOperator) {
|
|
193
|
-
parsedElements.push(Span({ class: "operator" }, term))
|
|
194
|
-
isTernaryOperator = false
|
|
195
|
-
} else {
|
|
196
|
-
parsedElements.push(Span({ class: "object-colon" }, c))
|
|
197
|
-
}
|
|
198
|
-
term = ""
|
|
199
|
-
index += 1
|
|
200
189
|
} else if (term.length == 0 && c === "'") {
|
|
201
190
|
isStringSingleQuote = true
|
|
202
191
|
term += c
|
|
@@ -218,7 +207,7 @@ function parseJavaScript(text) {
|
|
|
218
207
|
parsedElements.push(c)
|
|
219
208
|
term = ""
|
|
220
209
|
index += 1
|
|
221
|
-
} else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of") {
|
|
210
|
+
} else if (term == "import" || term == "new" || term == "async" || term == "await" || term == "for" || term == "while" || term == "of" || term == "from") {
|
|
222
211
|
parsedElements.push(Span({ class: "keyword" }, term))
|
|
223
212
|
parsedElements.push(c)
|
|
224
213
|
term = ""
|
|
@@ -229,20 +218,13 @@ function parseJavaScript(text) {
|
|
|
229
218
|
parsedElements.push(c)
|
|
230
219
|
term = ""
|
|
231
220
|
index += 1
|
|
232
|
-
} else if (
|
|
233
|
-
parsedElements.push(Span({ class: "number" }, term))
|
|
234
|
-
parsedElements.push(c)
|
|
235
|
-
term = ""
|
|
236
|
-
index += 1
|
|
237
|
-
}
|
|
238
|
-
else if (isFunctionDeclaration) {
|
|
221
|
+
} else if (isFunctionDeclaration) {
|
|
239
222
|
isFunctionDeclaration = false
|
|
240
223
|
parsedElements.push(Span({ class: "function-name" }, term))
|
|
241
224
|
parsedElements.push(c)
|
|
242
225
|
term = ""
|
|
243
226
|
index += 1
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
227
|
+
} else {
|
|
246
228
|
if (term.length > 0) {
|
|
247
229
|
index = pushWordTerm(parsedElements, term, index, text)
|
|
248
230
|
c = text[index]
|
|
@@ -273,8 +255,7 @@ function parseJavaScript(text) {
|
|
|
273
255
|
parsedElements.push(Span({ class: "spread-operator" }, term))
|
|
274
256
|
}
|
|
275
257
|
term = ""
|
|
276
|
-
}
|
|
277
|
-
else if (c === "(") {
|
|
258
|
+
} else if (c === "(") {
|
|
278
259
|
if (term === "") {
|
|
279
260
|
// skip
|
|
280
261
|
} else if (term == "require" || term == "isNaN") {
|
|
@@ -339,6 +320,14 @@ function parseJavaScript(text) {
|
|
|
339
320
|
if (term.length > 0) {
|
|
340
321
|
if (isSingleLineComment) {
|
|
341
322
|
parsedElements.push(Span({ class: "comment" }, term))
|
|
323
|
+
} else if (isNumber) {
|
|
324
|
+
if (term[term.length - 1] === "n") {
|
|
325
|
+
parsedElements.push(Span({ class: "bigint" }, term))
|
|
326
|
+
} else if (term.includes("n")) {
|
|
327
|
+
parsedElements.push(term)
|
|
328
|
+
} else {
|
|
329
|
+
parsedElements.push(Span({ class: "number" }, term))
|
|
330
|
+
}
|
|
342
331
|
} else {
|
|
343
332
|
pushWordTerm(parsedElements, term, index, text)
|
|
344
333
|
}
|
package/README.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
# ArcheHighlight
|
|
2
2
|
Syntax highlighting for [vanilla microfrontends](https://arche.gallery/). Converts JavaScript code into a React Element or HTML.
|
|
3
3
|
|
|
4
|
+
Source code: [GitHub](https://github.com/richytong/ArcheHighlight) |
|
|
5
|
+
License: [CFOSS](https://cloutsworld.com/en-us/legal/license/cfoss)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
[](https://codecov.io/gh/richytong/arche-highlight)
|
|
9
|
+
[](https://www.npmjs.com/package/arche-highlight)
|
|
10
|
+
|
|
11
|
+
|
|
4
12
|
```javascript
|
|
5
13
|
const ReactElement = Arche(React)
|
|
6
14
|
window.Span = ReactElement.Span
|