@ape-egg/codie 0.1.1 → 0.1.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/codie.js +1 -1
- package/constants.js +1 -0
- package/format.js +3 -2
- package/highlight-js.css +4 -0
- package/highlight.js +17 -8
- package/package.json +6 -3
- package/structure.css +4 -1
package/codie.js
CHANGED
|
@@ -61,7 +61,7 @@ const highlight = (code, modes, options = {}) => {
|
|
|
61
61
|
if (!modes.html) {
|
|
62
62
|
if (modes.json) return highlightJSON(escaped);
|
|
63
63
|
if (modes.css) return highlightCSS(escaped);
|
|
64
|
-
if (modes.js) return
|
|
64
|
+
if (modes.js) return highlightJSRaw(code);
|
|
65
65
|
return escaped;
|
|
66
66
|
}
|
|
67
67
|
|
package/constants.js
CHANGED
package/format.js
CHANGED
|
@@ -12,12 +12,13 @@ export const dedent = str => {
|
|
|
12
12
|
|
|
13
13
|
// Clean up boolean attributes for non-value attributes:
|
|
14
14
|
// attr="" → attr, attr="true" → attr, attr="false" → (removed)
|
|
15
|
+
// Vibe name bindings (@[expr]) count as attribute names too.
|
|
15
16
|
export const cleanupBooleanAttrs = html =>
|
|
16
17
|
html
|
|
17
|
-
.replace(/ ([\w-]
|
|
18
|
+
.replace(/ ([\w-]+|@\[[^\]]+\])="(?:true|)"/g, (match, attr) =>
|
|
18
19
|
VALUE_ATTRS.has(attr) ? match : ` ${attr}`
|
|
19
20
|
)
|
|
20
|
-
.replace(/ ([\w-]
|
|
21
|
+
.replace(/ ([\w-]+|@\[[^\]]+\])="false"/g, (match, attr) =>
|
|
21
22
|
VALUE_ATTRS.has(attr) ? match : ''
|
|
22
23
|
)
|
|
23
24
|
|
package/highlight-js.css
CHANGED
package/highlight.js
CHANGED
|
@@ -44,7 +44,7 @@ const highlightCommentVariables = (content) => {
|
|
|
44
44
|
export const highlightJS = (code, options = {}) => {
|
|
45
45
|
const tokens = [];
|
|
46
46
|
const tokenRegex =
|
|
47
|
-
/(@\[([^\]]+)\])|("(?:[^&]|&(?!quot;))*?")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|(
|
|
47
|
+
/(@\[([^\]]+)\])|("(?:[^&]|&(?!quot;))*?")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|((?<=^|\s)(?:\/\/|#)[^\n]*)|(\/\*[\s\S]*?\*\/)|(\$\.([a-zA-Z_][a-zA-Z0-9_]*))|(\b\d[\d_]*(?:\.[\d_]+)?\b)|(\b[a-zA-Z_][a-zA-Z0-9_]*\b)|([^\s])/g;
|
|
48
48
|
let match,
|
|
49
49
|
lastIndex = 0;
|
|
50
50
|
|
|
@@ -112,8 +112,10 @@ export const highlightJS = (code, options = {}) => {
|
|
|
112
112
|
// JavaScript highlighter for raw (unescaped) content
|
|
113
113
|
export const highlightJSRaw = (code) => {
|
|
114
114
|
const tokens = [];
|
|
115
|
+
// A command line: a bare lowercase word then arguments, on one full row — no JS
|
|
116
|
+
// keyword lead, no assignment/call/statement characters, no trailing continuation \
|
|
115
117
|
const tokenRegex =
|
|
116
|
-
/(<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s+[^>]*)?>)|("(?:[^"\\]|\\.)*")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|(
|
|
118
|
+
/(^[ \t]*(?!(?:import|export|const|let|var|return|await|async|function|if|else|for|while|new|typeof|throw)\b)[a-z][\w.-]*[ \t]+[^\n=(){};]*[^\n\\=(){};])$|(<\/?[a-zA-Z][a-zA-Z0-9-]*(?:\s+[^>]*)?>)|("(?:[^"\\]|\\.)*")|('(?:[^'\\]|\\.)*')|(`(?:[^`\\]|\\.)*`)|((?<=^|\s)(?:\/\/|#)[^\n]*)|(\/\*[\s\S]*?\*\/)|(\$\.([a-zA-Z_][a-zA-Z0-9_]*))|(\b\d[\d_]*(?:\.[\d_]+)?\b)|(\b[a-zA-Z_][a-zA-Z0-9_]*\b)|([^\s])/gm;
|
|
117
119
|
let match,
|
|
118
120
|
lastIndex = 0;
|
|
119
121
|
|
|
@@ -122,6 +124,7 @@ export const highlightJSRaw = (code) => {
|
|
|
122
124
|
|
|
123
125
|
const [
|
|
124
126
|
full,
|
|
127
|
+
commandLine,
|
|
125
128
|
htmlTag,
|
|
126
129
|
dblStr,
|
|
127
130
|
sglStr,
|
|
@@ -136,7 +139,9 @@ export const highlightJSRaw = (code) => {
|
|
|
136
139
|
] = match;
|
|
137
140
|
const escaped = escapeHTML(full);
|
|
138
141
|
|
|
139
|
-
if (
|
|
142
|
+
if (commandLine) {
|
|
143
|
+
tokens.push(span(CLASS.COMMAND, escaped));
|
|
144
|
+
} else if (htmlTag) {
|
|
140
145
|
const tagMatch = full.match(/^(<\/?)([a-zA-Z][a-zA-Z0-9-]*)([\s\S]*?)(>)$/);
|
|
141
146
|
if (tagMatch) {
|
|
142
147
|
const [, open, tagName, attrs, close] = tagMatch;
|
|
@@ -196,7 +201,7 @@ export const highlightJSRaw = (code) => {
|
|
|
196
201
|
// CSS highlighter
|
|
197
202
|
export const highlightCSS = (code, options = {}) => {
|
|
198
203
|
let result = '';
|
|
199
|
-
const ruleRegex = /(\/\*[\s\S]*?\*\/)|([^{}]+)(\{)([^}]*)(\})/g;
|
|
204
|
+
const ruleRegex = /(\/\*[\s\S]*?\*\/)|((?:[^{}\/]|\/(?!\*))+)(\{)([^}]*)(\})/g;
|
|
200
205
|
let match,
|
|
201
206
|
lastIndex = 0;
|
|
202
207
|
|
|
@@ -324,21 +329,25 @@ export const highlightHTML = (
|
|
|
324
329
|
span(CLASS.COMMENT, `<!--${highlightCommentVariables(content)}-->`),
|
|
325
330
|
);
|
|
326
331
|
|
|
327
|
-
// HTML tags with attributes
|
|
332
|
+
// HTML tags with attributes (attribute names can be @[...] name bindings)
|
|
328
333
|
highlighted = highlighted.replace(
|
|
329
|
-
/(<\/?)([a-zA-Z0-9\-]+)((?:\s+[a-zA-Z0-9\-:]
|
|
334
|
+
/(<\/?)([a-zA-Z0-9\-]+)((?:\s+(?:[a-zA-Z0-9\-:]+|@\[[^\]]+\])(?:=(?:"(?:(?!").)*?"|'[^']*'|[^\s>]+))?)*\s*)(\/?\s*>)/gs,
|
|
330
335
|
(fullMatch, open, tag, attrs, close) => {
|
|
331
336
|
let result = span(CLASS.PUNCTUATION, open) + span(CLASS.TAG, tag);
|
|
332
337
|
|
|
333
338
|
if (attrs) {
|
|
334
339
|
if (attrs.trim()) {
|
|
335
340
|
const attrRegex =
|
|
336
|
-
/([a-zA-Z0-9\-:]
|
|
341
|
+
/([a-zA-Z0-9\-:]+|@\[[^\]]+\])(=(?:"((?:(?!").)*?)"|'([^']*)'|([^\s>]+)))?/gs;
|
|
337
342
|
let attrMatch,
|
|
338
343
|
last = 0;
|
|
339
344
|
|
|
340
345
|
while ((attrMatch = attrRegex.exec(attrs)) !== null) {
|
|
341
|
-
result +=
|
|
346
|
+
result +=
|
|
347
|
+
attrs.substring(last, attrMatch.index) +
|
|
348
|
+
(attrMatch[1].startsWith('@[')
|
|
349
|
+
? highlightBindings(attrMatch[1])
|
|
350
|
+
: span(CLASS.ATTR_NAME, attrMatch[1]));
|
|
342
351
|
|
|
343
352
|
if (attrMatch[2]) {
|
|
344
353
|
result += span(CLASS.PUNCTUATION, '=');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ape-egg/codie",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Modular code display and editing package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "codie.js",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"syntax-highlighting",
|
|
22
22
|
"code-display"
|
|
23
23
|
],
|
|
24
|
-
"author": "
|
|
25
|
-
"license": "
|
|
24
|
+
"author": "kkortes",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
}
|
|
26
29
|
}
|
package/structure.css
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
display: grid;
|
|
6
6
|
position: relative;
|
|
7
7
|
width: 100%;
|
|
8
|
-
font-size: inherit;
|
|
8
|
+
font-size: var(--unit-size, inherit);
|
|
9
9
|
line-height: 1.5;
|
|
10
10
|
font-family:
|
|
11
11
|
'Geist Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New',
|
|
@@ -50,6 +50,9 @@
|
|
|
50
50
|
min-height: 100%;
|
|
51
51
|
border: none;
|
|
52
52
|
outline: none;
|
|
53
|
+
box-shadow: none;
|
|
54
|
+
border-radius: 0;
|
|
55
|
+
background: none;
|
|
53
56
|
resize: none;
|
|
54
57
|
overflow: hidden;
|
|
55
58
|
color: transparent;
|