ink-markdown-es 1.2.0 → 1.3.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/dist/index.js +1 -85
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -121,85 +121,6 @@ const BOX_STYLE_KEYS = [
|
|
|
121
121
|
'borderLeftDimColor',
|
|
122
122
|
'borderRightDimColor'
|
|
123
123
|
];
|
|
124
|
-
const TERMINAL_COLORS = {
|
|
125
|
-
comment: 'gray',
|
|
126
|
-
'comment.block': 'gray',
|
|
127
|
-
'comment.line': 'gray',
|
|
128
|
-
keyword: 'magenta',
|
|
129
|
-
'keyword.control': 'magenta',
|
|
130
|
-
'keyword.other': 'magenta',
|
|
131
|
-
string: 'green',
|
|
132
|
-
'string.quoted': 'green',
|
|
133
|
-
'string.regexp': 'red',
|
|
134
|
-
'entity.name.function': 'blue',
|
|
135
|
-
'support.function': 'blueBright',
|
|
136
|
-
'meta.function-call': 'blueBright',
|
|
137
|
-
variable: 'white',
|
|
138
|
-
'variable.parameter': 'yellowBright',
|
|
139
|
-
'variable.other': 'white',
|
|
140
|
-
'entity.name.type': 'cyan',
|
|
141
|
-
'entity.name.class': 'yellowBright',
|
|
142
|
-
'support.type': 'cyanBright',
|
|
143
|
-
'support.class': 'yellowBright',
|
|
144
|
-
'constant.numeric': 'yellow',
|
|
145
|
-
'constant.language': 'yellow',
|
|
146
|
-
operator: 'cyan',
|
|
147
|
-
punctuation: 'white',
|
|
148
|
-
'variable.other.property': 'blue',
|
|
149
|
-
'entity.other.attribute-name': 'blue',
|
|
150
|
-
'entity.name.tag': 'red',
|
|
151
|
-
'meta.tag': 'red',
|
|
152
|
-
'constant.language.boolean': 'yellow',
|
|
153
|
-
'constant.language.null': 'yellow',
|
|
154
|
-
meta: 'gray',
|
|
155
|
-
storage: 'magenta',
|
|
156
|
-
'storage.type': 'magenta'
|
|
157
|
-
};
|
|
158
|
-
function hexToTerminalColor(hex) {
|
|
159
|
-
const colorMap = {
|
|
160
|
-
'#6a737d': 'gray',
|
|
161
|
-
'#8b949e': 'gray',
|
|
162
|
-
'#6e7681': 'gray',
|
|
163
|
-
'#d73a49': 'magenta',
|
|
164
|
-
'#f97583': 'magenta',
|
|
165
|
-
'#ff7b72': 'red',
|
|
166
|
-
'#032f62': 'green',
|
|
167
|
-
'#22863a': 'green',
|
|
168
|
-
'#7ee787': 'green',
|
|
169
|
-
'#005cc5': 'blue',
|
|
170
|
-
'#0366d6': 'blue',
|
|
171
|
-
'#79c0ff': 'cyan',
|
|
172
|
-
'#58a6ff': 'blueBright',
|
|
173
|
-
'#a5d6ff': 'cyan',
|
|
174
|
-
'#e36209': 'yellow',
|
|
175
|
-
'#d29922': 'yellow',
|
|
176
|
-
'#ffa657': 'yellow',
|
|
177
|
-
'#0550ae': 'cyan'
|
|
178
|
-
};
|
|
179
|
-
const normalized = hex.toLowerCase();
|
|
180
|
-
if (colorMap[normalized]) return colorMap[normalized];
|
|
181
|
-
const r = Number.parseInt(normalized.slice(1, 3), 16);
|
|
182
|
-
const g = Number.parseInt(normalized.slice(3, 5), 16);
|
|
183
|
-
const b = Number.parseInt(normalized.slice(5, 7), 16);
|
|
184
|
-
const brightness = (299 * r + 587 * g + 114 * b) / 1000;
|
|
185
|
-
if (brightness < 80) return 'gray';
|
|
186
|
-
if (r > g && r > b) return 'red';
|
|
187
|
-
if (g > r && g > b) return 'green';
|
|
188
|
-
if (b > r && b > g) return 'blue';
|
|
189
|
-
if (r > 150 && g > 150) return 'yellow';
|
|
190
|
-
if (g > 150 && b > 150) return 'cyan';
|
|
191
|
-
if (r > 150 && b > 150) return 'magenta';
|
|
192
|
-
}
|
|
193
|
-
function tokenScopeToColor(scopes) {
|
|
194
|
-
for (const scope of scopes){
|
|
195
|
-
if (TERMINAL_COLORS[scope]) return TERMINAL_COLORS[scope];
|
|
196
|
-
const parts = scope.split('.');
|
|
197
|
-
for(let i = parts.length; i > 0; i--){
|
|
198
|
-
const key = parts.slice(0, i).join('.');
|
|
199
|
-
if (TERMINAL_COLORS[key]) return TERMINAL_COLORS[key];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
124
|
async function highlightCodeAsync(code, language, theme = 'github-dark') {
|
|
204
125
|
try {
|
|
205
126
|
const result = await codeToTokens(code, {
|
|
@@ -212,12 +133,7 @@ async function highlightCodeAsync(code, language, theme = 'github-dark') {
|
|
|
212
133
|
const line = result.tokens[lineIndex];
|
|
213
134
|
if (line) {
|
|
214
135
|
for (const token of line){
|
|
215
|
-
|
|
216
|
-
if (token.color) color = hexToTerminalColor(token.color);
|
|
217
|
-
if (!color && token.explanation) {
|
|
218
|
-
const scopes = token.explanation.map((e)=>e.scopes?.[0]?.scopeName || '');
|
|
219
|
-
color = tokenScopeToColor(scopes);
|
|
220
|
-
}
|
|
136
|
+
const color = token.color || void 0;
|
|
221
137
|
nodes.push(/*#__PURE__*/ jsx(Text, {
|
|
222
138
|
color: color,
|
|
223
139
|
children: token.content
|